ETH Price: $3,251.98 (+2.41%)
Gas: 4 Gwei

Contract

0x2a17c35FF147b32f13F19F2E311446eEB02503F3
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Token Holdings

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Create Staking P...130661992021-08-21 3:16:261070 days ago1629515786IN
0x: Staking
0 ETH0.0025176233.57726642
Create Staking P...116895162021-01-20 2:14:511283 days ago1611108891IN
0x: Staking
0 ETH0.0028170655.5
Transfer Ownersh...112063322020-11-06 21:51:511357 days ago1604699511IN
0x: Staking
0 ETH0.0004755820
Add Authorized A...112063262020-11-06 21:50:271357 days ago1604699427IN
0x: Staking
0 ETH0.0004756420
Join Staking Poo...109805942020-10-03 3:31:571392 days ago1601695917IN
0x: Staking
0 ETH0.00172440.0001
Join Staking Poo...109805942020-10-03 3:31:571392 days ago1601695917IN
0x: Staking
0 ETH0.00172440.0001
Join Staking Poo...97959912020-04-03 1:20:431575 days ago1585876843IN
0x: Staking
0 ETH0.000047411.1
Create Staking P...93124402020-01-19 14:57:191649 days ago1579445839IN
0x: Staking
0 ETH0.000050751
Create Staking P...93123502020-01-19 14:37:111649 days ago1579444631IN
0x: Staking
0 ETH0.000050731
Create Staking P...91756182019-12-28 11:38:191671 days ago1577533099IN
0x: Staking
0 ETH0.000076131.5
Join Staking Poo...90400072019-12-02 20:48:091697 days ago1575319689IN
0x: Staking
0 ETH0.000056722
Join Staking Poo...90398662019-12-02 20:12:551697 days ago1575317575IN
0x: Staking
0 ETH0.000086722
Create Staking P...90391432019-12-02 17:02:371697 days ago1575306157IN
0x: Staking
0 ETH0.000129842
0x6080604089525782019-11-17 20:57:041712 days ago1574024224IN
 Create: Staking
0 ETH0.0587481810

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
Staking

Compiler Version
v0.5.12+commit.7709ece9

Optimization Enabled:
Yes with 1000000 runs

Other Settings:
constantinople EvmVersion, None license
File 1 of 58 : Staking.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;
pragma experimental ABIEncoderV2;

import "./interfaces/IStaking.sol";
import "./sys/MixinParams.sol";
import "./stake/MixinStake.sol";
import "./fees/MixinExchangeFees.sol";


contract Staking is
    IStaking,
    MixinParams,
    MixinStake,
    MixinExchangeFees
{
    /// @dev Initialize storage owned by this contract.
    ///      This function should not be called directly.
    ///      The StakingProxy contract will call it in `attachStakingContract()`.
    function init()
        public
        onlyAuthorized
    {
        // DANGER! When performing upgrades, take care to modify this logic
        // to prevent accidentally clearing prior state.
        _initMixinScheduler();
        _initMixinParams();
    }
}

File 2 of 58 : IStaking.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;
pragma experimental ABIEncoderV2;

import "@0x/contracts-erc20/contracts/src/interfaces/IEtherToken.sol";
import "./IStructs.sol";
import "./IZrxVault.sol";


interface IStaking {

    /// @dev Adds a new exchange address
    /// @param addr Address of exchange contract to add
    function addExchangeAddress(address addr)
        external;

    /// @dev Create a new staking pool. The sender will be the operator of this pool.
    /// Note that an operator must be payable.
    /// @param operatorShare Portion of rewards owned by the operator, in ppm.
    /// @param addOperatorAsMaker Adds operator to the created pool as a maker for convenience iff true.
    /// @return poolId The unique pool id generated for this pool.
    function createStakingPool(uint32 operatorShare, bool addOperatorAsMaker)
        external
        returns (bytes32 poolId);

    /// @dev Decreases the operator share for the given pool (i.e. increases pool rewards for members).
    /// @param poolId Unique Id of pool.
    /// @param newOperatorShare The newly decreased percentage of any rewards owned by the operator.
    function decreaseStakingPoolOperatorShare(bytes32 poolId, uint32 newOperatorShare)
        external;

    /// @dev Begins a new epoch, preparing the prior one for finalization.
    ///      Throws if not enough time has passed between epochs or if the
    ///      previous epoch was not fully finalized.
    /// @return numPoolsToFinalize The number of unfinalized pools.
    function endEpoch()
        external
        returns (uint256);

    /// @dev Instantly finalizes a single pool that earned rewards in the previous
    ///      epoch, crediting it rewards for members and withdrawing operator's
    ///      rewards as WETH. This can be called by internal functions that need
    ///      to finalize a pool immediately. Does nothing if the pool is already
    ///      finalized or did not earn rewards in the previous epoch.
    /// @param poolId The pool ID to finalize.
    function finalizePool(bytes32 poolId)
        external;

    /// @dev Initialize storage owned by this contract.
    ///      This function should not be called directly.
    ///      The StakingProxy contract will call it in `attachStakingContract()`.
    function init()
        external;

    /// @dev Allows caller to join a staking pool as a maker.
    /// @param poolId Unique id of pool.
    function joinStakingPoolAsMaker(bytes32 poolId)
        external;

    /// @dev Moves stake between statuses: 'undelegated' or 'delegated'.
    ///      Delegated stake can also be moved between pools.
    ///      This change comes into effect next epoch.
    /// @param from status to move stake out of.
    /// @param to status to move stake into.
    /// @param amount of stake to move.
    function moveStake(
        IStructs.StakeInfo calldata from,
        IStructs.StakeInfo calldata to,
        uint256 amount
    )
        external;

    /// @dev Pays a protocol fee in ETH.
    /// @param makerAddress The address of the order's maker.
    /// @param payerAddress The address that is responsible for paying the protocol fee.
    /// @param protocolFee The amount of protocol fees that should be paid.
    function payProtocolFee(
        address makerAddress,
        address payerAddress,
        uint256 protocolFee
    )
        external
        payable;

    /// @dev Removes an existing exchange address
    /// @param addr Address of exchange contract to remove
    function removeExchangeAddress(address addr)
        external;

    /// @dev Set all configurable parameters at once.
    /// @param _epochDurationInSeconds Minimum seconds between epochs.
    /// @param _rewardDelegatedStakeWeight How much delegated stake is weighted vs operator stake, in ppm.
    /// @param _minimumPoolStake Minimum amount of stake required in a pool to collect rewards.
    /// @param _cobbDouglasAlphaNumerator Numerator for cobb douglas alpha factor.
    /// @param _cobbDouglasAlphaDenominator Denominator for cobb douglas alpha factor.
    function setParams(
        uint256 _epochDurationInSeconds,
        uint32 _rewardDelegatedStakeWeight,
        uint256 _minimumPoolStake,
        uint32 _cobbDouglasAlphaNumerator,
        uint32 _cobbDouglasAlphaDenominator
    )
        external;

    /// @dev Stake ZRX tokens. Tokens are deposited into the ZRX Vault.
    ///      Unstake to retrieve the ZRX. Stake is in the 'Active' status.
    /// @param amount of ZRX to stake.
    function stake(uint256 amount)
        external;

    /// @dev Unstake. Tokens are withdrawn from the ZRX Vault and returned to
    ///      the staker. Stake must be in the 'undelegated' status in both the
    ///      current and next epoch in order to be unstaked.
    /// @param amount of ZRX to unstake.
    function unstake(uint256 amount)
        external;

    /// @dev Withdraws the caller's WETH rewards that have accumulated
    ///      until the last epoch.
    /// @param poolId Unique id of pool.
    function withdrawDelegatorRewards(bytes32 poolId)
        external;

    /// @dev Computes the reward balance in ETH of a specific member of a pool.
    /// @param poolId Unique id of pool.
    /// @param member The member of the pool.
    /// @return totalReward Balance in ETH.
    function computeRewardBalanceOfDelegator(bytes32 poolId, address member)
        external
        view
        returns (uint256 reward);

    /// @dev Computes the reward balance in ETH of the operator of a pool.
    /// @param poolId Unique id of pool.
    /// @return totalReward Balance in ETH.
    function computeRewardBalanceOfOperator(bytes32 poolId)
        external
        view
        returns (uint256 reward);

    /// @dev Returns the earliest end time in seconds of this epoch.
    ///      The next epoch can begin once this time is reached.
    ///      Epoch period = [startTimeInSeconds..endTimeInSeconds)
    /// @return Time in seconds.
    function getCurrentEpochEarliestEndTimeInSeconds()
        external
        view
        returns (uint256);

    /// @dev Gets global stake for a given status.
    /// @param stakeStatus UNDELEGATED or DELEGATED
    /// @return Global stake for given status.
    function getGlobalStakeByStatus(IStructs.StakeStatus stakeStatus)
        external
        view
        returns (IStructs.StoredBalance memory balance);

    /// @dev Gets an owner's stake balances by status.
    /// @param staker Owner of stake.
    /// @param stakeStatus UNDELEGATED or DELEGATED
    /// @return Owner's stake balances for given status.
    function getOwnerStakeByStatus(
        address staker,
        IStructs.StakeStatus stakeStatus
    )
        external
        view
        returns (IStructs.StoredBalance memory balance);

    /// @dev Retrieves all configurable parameter values.
    /// @return _epochDurationInSeconds Minimum seconds between epochs.
    /// @return _rewardDelegatedStakeWeight How much delegated stake is weighted vs operator stake, in ppm.
    /// @return _minimumPoolStake Minimum amount of stake required in a pool to collect rewards.
    /// @return _cobbDouglasAlphaNumerator Numerator for cobb douglas alpha factor.
    /// @return _cobbDouglasAlphaDenominator Denominator for cobb douglas alpha factor.
    function getParams()
        external
        view
        returns (
            uint256 _epochDurationInSeconds,
            uint32 _rewardDelegatedStakeWeight,
            uint256 _minimumPoolStake,
            uint32 _cobbDouglasAlphaNumerator,
            uint32 _cobbDouglasAlphaDenominator
        );

    /// @param staker of stake.
    /// @param poolId Unique Id of pool.
    /// @return Stake delegated to pool by staker.
    function getStakeDelegatedToPoolByOwner(address staker, bytes32 poolId)
        external
        view
        returns (IStructs.StoredBalance memory balance);

    /// @dev Returns a staking pool
    /// @param poolId Unique id of pool.
    function getStakingPool(bytes32 poolId)
        external
        view
        returns (IStructs.Pool memory);

    /// @dev Get stats on a staking pool in this epoch.
    /// @param poolId Pool Id to query.
    /// @return PoolStats struct for pool id.
    function getStakingPoolStatsThisEpoch(bytes32 poolId)
        external
        view
        returns (IStructs.PoolStats memory);

    /// @dev Returns the total stake delegated to a specific staking pool,
    ///      across all members.
    /// @param poolId Unique Id of pool.
    /// @return Total stake delegated to pool.
    function getTotalStakeDelegatedToPool(bytes32 poolId)
        external
        view
        returns (IStructs.StoredBalance memory balance);

    /// @dev An overridable way to access the deployed WETH contract.
    ///      Must be view to allow overrides to access state.
    /// @return wethContract The WETH contract instance.
    function getWethContract()
        external
        view
        returns (IEtherToken wethContract);

    /// @dev An overridable way to access the deployed zrxVault.
    ///      Must be view to allow overrides to access state.
    /// @return zrxVault The zrxVault contract.
    function getZrxVault()
        external
        view
        returns (IZrxVault zrxVault);
}

File 3 of 58 : IEtherToken.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;

import "./IERC20Token.sol";


contract IEtherToken is
    IERC20Token
{
    function deposit()
        public
        payable;
    
    function withdraw(uint256 amount)
        public;
}

File 4 of 58 : IERC20Token.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;


contract IERC20Token {

    // solhint-disable no-simple-event-func-name
    event Transfer(
        address indexed _from,
        address indexed _to,
        uint256 _value
    );

    event Approval(
        address indexed _owner,
        address indexed _spender,
        uint256 _value
    );

    /// @dev send `value` token to `to` from `msg.sender`
    /// @param _to The address of the recipient
    /// @param _value The amount of token to be transferred
    /// @return True if transfer was successful
    function transfer(address _to, uint256 _value)
        external
        returns (bool);

    /// @dev send `value` token to `to` from `from` on the condition it is approved by `from`
    /// @param _from The address of the sender
    /// @param _to The address of the recipient
    /// @param _value The amount of token to be transferred
    /// @return True if transfer was successful
    function transferFrom(
        address _from,
        address _to,
        uint256 _value
    )
        external
        returns (bool);

    /// @dev `msg.sender` approves `_spender` to spend `_value` tokens
    /// @param _spender The address of the account able to transfer the tokens
    /// @param _value The amount of wei to be approved for transfer
    /// @return Always true if the call has enough gas to complete execution
    function approve(address _spender, uint256 _value)
        external
        returns (bool);

    /// @dev Query total supply of token
    /// @return Total supply of token
    function totalSupply()
        external
        view
        returns (uint256);

    /// @param _owner The address from which the balance will be retrieved
    /// @return Balance of owner
    function balanceOf(address _owner)
        external
        view
        returns (uint256);

    /// @param _owner The address of the account owning tokens
    /// @param _spender The address of the account able to transfer the tokens
    /// @return Amount of remaining tokens allowed to spent
    function allowance(address _owner, address _spender)
        external
        view
        returns (uint256);
}

File 5 of 58 : IStructs.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;


interface IStructs {

    /// @dev Stats for a pool that earned rewards.
    /// @param feesCollected Fees collected in ETH by this pool.
    /// @param weightedStake Amount of weighted stake in the pool.
    /// @param membersStake Amount of non-operator stake in the pool.
    struct PoolStats {
        uint256 feesCollected;
        uint256 weightedStake;
        uint256 membersStake;
    }

    /// @dev Holds stats aggregated across a set of pools.
    /// @param rewardsAvailable Rewards (ETH) available to the epoch
    ///        being finalized (the previous epoch). This is simply the balance
    ///        of the contract at the end of the epoch.
    /// @param numPoolsToFinalize The number of pools that have yet to be finalized through `finalizePools()`.
    /// @param totalFeesCollected The total fees collected for the epoch being finalized.
    /// @param totalWeightedStake The total fees collected for the epoch being finalized.
    /// @param totalRewardsFinalized Amount of rewards that have been paid during finalization.
    struct AggregatedStats {
        uint256 rewardsAvailable;
        uint256 numPoolsToFinalize;
        uint256 totalFeesCollected;
        uint256 totalWeightedStake;
        uint256 totalRewardsFinalized;
    }

    /// @dev Encapsulates a balance for the current and next epochs.
    /// Note that these balances may be stale if the current epoch
    /// is greater than `currentEpoch`.
    /// @param currentEpoch the current epoch
    /// @param currentEpochBalance balance in the current epoch.
    /// @param nextEpochBalance balance in `currentEpoch+1`.
    struct StoredBalance {
        uint64 currentEpoch;
        uint96 currentEpochBalance;
        uint96 nextEpochBalance;
    }

    /// @dev Statuses that stake can exist in.
    ///      Any stake can be (re)delegated effective at the next epoch
    ///      Undelegated stake can be withdrawn if it is available in both the current and next epoch
    enum StakeStatus {
        UNDELEGATED,
        DELEGATED
    }

    /// @dev Info used to describe a status.
    /// @param status of the stake.
    /// @param poolId Unique Id of pool. This is set when status=DELEGATED.
    struct StakeInfo {
        StakeStatus status;
        bytes32 poolId;
    }

    /// @dev Struct to represent a fraction.
    /// @param numerator of fraction.
    /// @param denominator of fraction.
    struct Fraction {
        uint256 numerator;
        uint256 denominator;
    }

    /// @dev Holds the metadata for a staking pool.
    /// @param operator of the pool.
    /// @param operatorShare Fraction of the total balance owned by the operator, in ppm.
    struct Pool {
        address operator;
        uint32 operatorShare;
    }
}

File 6 of 58 : IZrxVault.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;


interface IZrxVault {

    /// @dev Emmitted whenever a StakingProxy is set in a vault.
    event StakingProxySet(address stakingProxyAddress);

    /// @dev Emitted when the Staking contract is put into Catastrophic Failure Mode
    /// @param sender Address of sender (`msg.sender`)
    event InCatastrophicFailureMode(address sender);

    /// @dev Emitted when Zrx Tokens are deposited into the vault.
    /// @param staker of Zrx Tokens.
    /// @param amount of Zrx Tokens deposited.
    event Deposit(
        address indexed staker,
        uint256 amount
    );

    /// @dev Emitted when Zrx Tokens are withdrawn from the vault.
    /// @param staker of Zrx Tokens.
    /// @param amount of Zrx Tokens withdrawn.
    event Withdraw(
        address indexed staker,
        uint256 amount
    );

    /// @dev Emitted whenever the ZRX AssetProxy is set.
    event ZrxProxySet(address zrxProxyAddress);

    /// @dev Sets the address of the StakingProxy contract.
    /// Note that only the contract staker can call this function.
    /// @param _stakingProxyAddress Address of Staking proxy contract.
    function setStakingProxy(address _stakingProxyAddress)
        external;

    /// @dev Vault enters into Catastrophic Failure Mode.
    /// *** WARNING - ONCE IN CATOSTROPHIC FAILURE MODE, YOU CAN NEVER GO BACK! ***
    /// Note that only the contract staker can call this function.
    function enterCatastrophicFailure()
        external;

    /// @dev Sets the Zrx proxy.
    /// Note that only the contract staker can call this.
    /// Note that this can only be called when *not* in Catastrophic Failure mode.
    /// @param zrxProxyAddress Address of the 0x Zrx Proxy.
    function setZrxProxy(address zrxProxyAddress)
        external;

    /// @dev Deposit an `amount` of Zrx Tokens from `staker` into the vault.
    /// Note that only the Staking contract can call this.
    /// Note that this can only be called when *not* in Catastrophic Failure mode.
    /// @param staker of Zrx Tokens.
    /// @param amount of Zrx Tokens to deposit.
    function depositFrom(address staker, uint256 amount)
        external;

    /// @dev Withdraw an `amount` of Zrx Tokens to `staker` from the vault.
    /// Note that only the Staking contract can call this.
    /// Note that this can only be called when *not* in Catastrophic Failure mode.
    /// @param staker of Zrx Tokens.
    /// @param amount of Zrx Tokens to withdraw.
    function withdrawFrom(address staker, uint256 amount)
        external;

    /// @dev Withdraw ALL Zrx Tokens to `staker` from the vault.
    /// Note that this can only be called when *in* Catastrophic Failure mode.
    /// @param staker of Zrx Tokens.
    function withdrawAllFrom(address staker)
        external
        returns (uint256);

    /// @dev Returns the balance in Zrx Tokens of the `staker`
    /// @return Balance in Zrx.
    function balanceOf(address staker)
        external
        view
        returns (uint256);

    /// @dev Returns the entire balance of Zrx tokens in the vault.
    function balanceOfZrxVault()
        external
        view
        returns (uint256);
}

File 7 of 58 : MixinParams.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;

import "@0x/contracts-utils/contracts/src/LibRichErrors.sol";
import "../immutable/MixinStorage.sol";
import "../immutable/MixinConstants.sol";
import "../interfaces/IStakingEvents.sol";
import "../interfaces/IStakingProxy.sol";
import "../libs/LibStakingRichErrors.sol";


contract MixinParams is
    IStakingEvents,
    MixinStorage,
    MixinConstants
{
    /// @dev Set all configurable parameters at once.
    /// @param _epochDurationInSeconds Minimum seconds between epochs.
    /// @param _rewardDelegatedStakeWeight How much delegated stake is weighted vs operator stake, in ppm.
    /// @param _minimumPoolStake Minimum amount of stake required in a pool to collect rewards.
    /// @param _cobbDouglasAlphaNumerator Numerator for cobb douglas alpha factor.
    /// @param _cobbDouglasAlphaDenominator Denominator for cobb douglas alpha factor.
    function setParams(
        uint256 _epochDurationInSeconds,
        uint32 _rewardDelegatedStakeWeight,
        uint256 _minimumPoolStake,
        uint32 _cobbDouglasAlphaNumerator,
        uint32 _cobbDouglasAlphaDenominator
    )
        external
        onlyAuthorized
    {
        _setParams(
            _epochDurationInSeconds,
            _rewardDelegatedStakeWeight,
            _minimumPoolStake,
            _cobbDouglasAlphaNumerator,
            _cobbDouglasAlphaDenominator
        );

        // Let the staking proxy enforce that these parameters are within
        // acceptable ranges.
        IStakingProxy(address(this)).assertValidStorageParams();
    }

    /// @dev Retrieves all configurable parameter values.
    /// @return _epochDurationInSeconds Minimum seconds between epochs.
    /// @return _rewardDelegatedStakeWeight How much delegated stake is weighted vs operator stake, in ppm.
    /// @return _minimumPoolStake Minimum amount of stake required in a pool to collect rewards.
    /// @return _cobbDouglasAlphaNumerator Numerator for cobb douglas alpha factor.
    /// @return _cobbDouglasAlphaDenominator Denominator for cobb douglas alpha factor.
    function getParams()
        external
        view
        returns (
            uint256 _epochDurationInSeconds,
            uint32 _rewardDelegatedStakeWeight,
            uint256 _minimumPoolStake,
            uint32 _cobbDouglasAlphaNumerator,
            uint32 _cobbDouglasAlphaDenominator
        )
    {
        _epochDurationInSeconds = epochDurationInSeconds;
        _rewardDelegatedStakeWeight = rewardDelegatedStakeWeight;
        _minimumPoolStake = minimumPoolStake;
        _cobbDouglasAlphaNumerator = cobbDouglasAlphaNumerator;
        _cobbDouglasAlphaDenominator = cobbDouglasAlphaDenominator;
    }

    /// @dev Initialize storage belonging to this mixin.
    function _initMixinParams()
        internal
    {
        // Ensure state is uninitialized.
        _assertParamsNotInitialized();

        // Set up defaults.
        uint256 _epochDurationInSeconds = 10 days;
        uint32 _rewardDelegatedStakeWeight = (90 * PPM_DENOMINATOR) / 100;
        uint256 _minimumPoolStake = 100 * MIN_TOKEN_VALUE;
        uint32 _cobbDouglasAlphaNumerator = 2;
        uint32 _cobbDouglasAlphaDenominator = 3;

        _setParams(
            _epochDurationInSeconds,
            _rewardDelegatedStakeWeight,
            _minimumPoolStake,
            _cobbDouglasAlphaNumerator,
            _cobbDouglasAlphaDenominator
        );
    }

    /// @dev Asserts that upgradable storage has not yet been initialized.
    function _assertParamsNotInitialized()
        internal
        view
    {
        if (epochDurationInSeconds != 0 &&
            rewardDelegatedStakeWeight != 0 &&
            minimumPoolStake != 0 &&
            cobbDouglasAlphaNumerator != 0 &&
            cobbDouglasAlphaDenominator != 0
        ) {
            LibRichErrors.rrevert(
                LibStakingRichErrors.InitializationError(
                    LibStakingRichErrors.InitializationErrorCodes.MixinParamsAlreadyInitialized
                )
            );
        }
    }

    /// @dev Set all configurable parameters at once.
    /// @param _epochDurationInSeconds Minimum seconds between epochs.
    /// @param _rewardDelegatedStakeWeight How much delegated stake is weighted vs operator stake, in ppm.
    /// @param _minimumPoolStake Minimum amount of stake required in a pool to collect rewards.
    /// @param _cobbDouglasAlphaNumerator Numerator for cobb douglas alpha factor.
    /// @param _cobbDouglasAlphaDenominator Denominator for cobb douglas alpha factor.
    function _setParams(
        uint256 _epochDurationInSeconds,
        uint32 _rewardDelegatedStakeWeight,
        uint256 _minimumPoolStake,
        uint32 _cobbDouglasAlphaNumerator,
        uint32 _cobbDouglasAlphaDenominator
    )
        private
    {
        epochDurationInSeconds = _epochDurationInSeconds;
        rewardDelegatedStakeWeight = _rewardDelegatedStakeWeight;
        minimumPoolStake = _minimumPoolStake;
        cobbDouglasAlphaNumerator = _cobbDouglasAlphaNumerator;
        cobbDouglasAlphaDenominator = _cobbDouglasAlphaDenominator;

        emit ParamsSet(
            _epochDurationInSeconds,
            _rewardDelegatedStakeWeight,
            _minimumPoolStake,
            _cobbDouglasAlphaNumerator,
            _cobbDouglasAlphaDenominator
        );
    }
}

File 8 of 58 : LibRichErrors.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;


library LibRichErrors {

    // bytes4(keccak256("Error(string)"))
    bytes4 internal constant STANDARD_ERROR_SELECTOR =
        0x08c379a0;

    // solhint-disable func-name-mixedcase
    /// @dev ABI encode a standard, string revert error payload.
    ///      This is the same payload that would be included by a `revert(string)`
    ///      solidity statement. It has the function signature `Error(string)`.
    /// @param message The error string.
    /// @return The ABI encoded error.
    function StandardError(
        string memory message
    )
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            STANDARD_ERROR_SELECTOR,
            bytes(message)
        );
    }
    // solhint-enable func-name-mixedcase

    /// @dev Reverts an encoded rich revert reason `errorData`.
    /// @param errorData ABI encoded error data.
    function rrevert(bytes memory errorData)
        internal
        pure
    {
        assembly {
            revert(add(errorData, 0x20), mload(errorData))
        }
    }
}

File 9 of 58 : MixinStorage.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;
pragma experimental ABIEncoderV2;

import "@0x/contracts-utils/contracts/src/LibRichErrors.sol";
import "@0x/contracts-utils/contracts/src/Authorizable.sol";
import "./MixinConstants.sol";
import "../interfaces/IZrxVault.sol";
import "../interfaces/IStructs.sol";
import "../libs/LibStakingRichErrors.sol";


// solhint-disable max-states-count, no-empty-blocks
contract MixinStorage is
    Authorizable
{
    // address of staking contract
    address public stakingContract;

    // mapping from StakeStatus to global stored balance
    // NOTE: only Status.DELEGATED is used to access this mapping, but this format
    // is used for extensibility
    mapping (uint8 => IStructs.StoredBalance) internal _globalStakeByStatus;

    // mapping from StakeStatus to address of staker to stored balance
    mapping (uint8 => mapping (address => IStructs.StoredBalance)) internal _ownerStakeByStatus;

    // Mapping from Owner to Pool Id to Amount Delegated
    mapping (address => mapping (bytes32 => IStructs.StoredBalance)) internal _delegatedStakeToPoolByOwner;

    // Mapping from Pool Id to Amount Delegated
    mapping (bytes32 => IStructs.StoredBalance) internal _delegatedStakeByPoolId;

    // tracking Pool Id, a unique identifier for each staking pool.
    bytes32 public lastPoolId;

    // mapping from Maker Address to Pool Id of maker
    mapping (address => bytes32) public poolIdByMaker;

    // mapping from Pool Id to Pool
    mapping (bytes32 => IStructs.Pool) internal _poolById;

    // mapping from PoolId to balance of members
    mapping (bytes32 => uint256) public rewardsByPoolId;

    // current epoch
    uint256 public currentEpoch;

    // current epoch start time
    uint256 public currentEpochStartTimeInSeconds;

    // mapping from Pool Id to Epoch to Reward Ratio
    mapping (bytes32 => mapping (uint256 => IStructs.Fraction)) internal _cumulativeRewardsByPool;

    // mapping from Pool Id to Epoch
    mapping (bytes32 => uint256) internal _cumulativeRewardsByPoolLastStored;

    // registered 0x Exchange contracts
    mapping (address => bool) public validExchanges;

    /* Tweakable parameters */

    // Minimum seconds between epochs.
    uint256 public epochDurationInSeconds;

    // How much delegated stake is weighted vs operator stake, in ppm.
    uint32 public rewardDelegatedStakeWeight;

    // Minimum amount of stake required in a pool to collect rewards.
    uint256 public minimumPoolStake;

    // Numerator for cobb douglas alpha factor.
    uint32 public cobbDouglasAlphaNumerator;

    // Denominator for cobb douglas alpha factor.
    uint32 public cobbDouglasAlphaDenominator;

    /* State for finalization */

    /// @dev Stats for each pool that generated fees with sufficient stake to earn rewards.
    ///      See `_minimumPoolStake` in MixinParams.
    mapping (bytes32 => mapping (uint256 => IStructs.PoolStats)) public poolStatsByEpoch;

    /// @dev Aggregated stats across all pools that generated fees with sufficient stake to earn rewards.
    ///      See `_minimumPoolStake` in MixinParams.
    mapping (uint256 => IStructs.AggregatedStats) public aggregatedStatsByEpoch;

    /// @dev The WETH balance of this contract that is reserved for pool reward payouts.
    uint256 public wethReservedForPoolRewards;
}

File 10 of 58 : Authorizable.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;

import "./interfaces/IAuthorizable.sol";
import "./LibAuthorizableRichErrors.sol";
import "./LibRichErrors.sol";
import "./Ownable.sol";


// solhint-disable no-empty-blocks
contract Authorizable is
    Ownable,
    IAuthorizable
{
    /// @dev Only authorized addresses can invoke functions with this modifier.
    modifier onlyAuthorized {
        _assertSenderIsAuthorized();
        _;
    }

    mapping (address => bool) public authorized;
    address[] public authorities;

    /// @dev Initializes the `owner` address.
    constructor()
        public
        Ownable()
    {}

    /// @dev Authorizes an address.
    /// @param target Address to authorize.
    function addAuthorizedAddress(address target)
        external
        onlyOwner
    {
        _addAuthorizedAddress(target);
    }

    /// @dev Removes authorizion of an address.
    /// @param target Address to remove authorization from.
    function removeAuthorizedAddress(address target)
        external
        onlyOwner
    {
        if (!authorized[target]) {
            LibRichErrors.rrevert(LibAuthorizableRichErrors.TargetNotAuthorizedError(target));
        }
        for (uint256 i = 0; i < authorities.length; i++) {
            if (authorities[i] == target) {
                _removeAuthorizedAddressAtIndex(target, i);
                break;
            }
        }
    }

    /// @dev Removes authorizion of an address.
    /// @param target Address to remove authorization from.
    /// @param index Index of target in authorities array.
    function removeAuthorizedAddressAtIndex(
        address target,
        uint256 index
    )
        external
        onlyOwner
    {
        _removeAuthorizedAddressAtIndex(target, index);
    }

    /// @dev Gets all authorized addresses.
    /// @return Array of authorized addresses.
    function getAuthorizedAddresses()
        external
        view
        returns (address[] memory)
    {
        return authorities;
    }

    /// @dev Reverts if msg.sender is not authorized.
    function _assertSenderIsAuthorized()
        internal
        view
    {
        if (!authorized[msg.sender]) {
            LibRichErrors.rrevert(LibAuthorizableRichErrors.SenderNotAuthorizedError(msg.sender));
        }
    }

    /// @dev Authorizes an address.
    /// @param target Address to authorize.
    function _addAuthorizedAddress(address target)
        internal
    {
        // Ensure that the target is not the zero address.
        if (target == address(0)) {
            LibRichErrors.rrevert(LibAuthorizableRichErrors.ZeroCantBeAuthorizedError());
        }

        // Ensure that the target is not already authorized.
        if (authorized[target]) {
            LibRichErrors.rrevert(LibAuthorizableRichErrors.TargetAlreadyAuthorizedError(target));
        }

        authorized[target] = true;
        authorities.push(target);
        emit AuthorizedAddressAdded(target, msg.sender);
    }

    /// @dev Removes authorizion of an address.
    /// @param target Address to remove authorization from.
    /// @param index Index of target in authorities array.
    function _removeAuthorizedAddressAtIndex(
        address target,
        uint256 index
    )
        internal
    {
        if (!authorized[target]) {
            LibRichErrors.rrevert(LibAuthorizableRichErrors.TargetNotAuthorizedError(target));
        }
        if (index >= authorities.length) {
            LibRichErrors.rrevert(LibAuthorizableRichErrors.IndexOutOfBoundsError(
                index,
                authorities.length
            ));
        }
        if (authorities[index] != target) {
            LibRichErrors.rrevert(LibAuthorizableRichErrors.AuthorizedAddressMismatchError(
                authorities[index],
                target
            ));
        }

        delete authorized[target];
        authorities[index] = authorities[authorities.length - 1];
        authorities.length -= 1;
        emit AuthorizedAddressRemoved(target, msg.sender);
    }
}

File 11 of 58 : IAuthorizable.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;

import "./IOwnable.sol";


contract IAuthorizable is
    IOwnable
{
    // Event logged when a new address is authorized.
    event AuthorizedAddressAdded(
        address indexed target,
        address indexed caller
    );

    // Event logged when a currently authorized address is unauthorized.
    event AuthorizedAddressRemoved(
        address indexed target,
        address indexed caller
    );

    /// @dev Authorizes an address.
    /// @param target Address to authorize.
    function addAuthorizedAddress(address target)
        external;

    /// @dev Removes authorizion of an address.
    /// @param target Address to remove authorization from.
    function removeAuthorizedAddress(address target)
        external;

    /// @dev Removes authorizion of an address.
    /// @param target Address to remove authorization from.
    /// @param index Index of target in authorities array.
    function removeAuthorizedAddressAtIndex(
        address target,
        uint256 index
    )
        external;

    /// @dev Gets all authorized addresses.
    /// @return Array of authorized addresses.
    function getAuthorizedAddresses()
        external
        view
        returns (address[] memory);
}

File 12 of 58 : IOwnable.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;


contract IOwnable {

    /// @dev Emitted by Ownable when ownership is transferred.
    /// @param previousOwner The previous owner of the contract.
    /// @param newOwner The new owner of the contract.
    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /// @dev Transfers ownership of the contract to a new address.
    /// @param newOwner The address that will become the owner.
    function transferOwnership(address newOwner)
        public;
}

File 13 of 58 : LibAuthorizableRichErrors.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;


library LibAuthorizableRichErrors {

    // bytes4(keccak256("AuthorizedAddressMismatchError(address,address)"))
    bytes4 internal constant AUTHORIZED_ADDRESS_MISMATCH_ERROR_SELECTOR =
        0x140a84db;

    // bytes4(keccak256("IndexOutOfBoundsError(uint256,uint256)"))
    bytes4 internal constant INDEX_OUT_OF_BOUNDS_ERROR_SELECTOR =
        0xe9f83771;

    // bytes4(keccak256("SenderNotAuthorizedError(address)"))
    bytes4 internal constant SENDER_NOT_AUTHORIZED_ERROR_SELECTOR =
        0xb65a25b9;

    // bytes4(keccak256("TargetAlreadyAuthorizedError(address)"))
    bytes4 internal constant TARGET_ALREADY_AUTHORIZED_ERROR_SELECTOR =
        0xde16f1a0;

    // bytes4(keccak256("TargetNotAuthorizedError(address)"))
    bytes4 internal constant TARGET_NOT_AUTHORIZED_ERROR_SELECTOR =
        0xeb5108a2;

    // bytes4(keccak256("ZeroCantBeAuthorizedError()"))
    bytes internal constant ZERO_CANT_BE_AUTHORIZED_ERROR_BYTES =
        hex"57654fe4";

    // solhint-disable func-name-mixedcase
    function AuthorizedAddressMismatchError(
        address authorized,
        address target
    )
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            AUTHORIZED_ADDRESS_MISMATCH_ERROR_SELECTOR,
            authorized,
            target
        );
    }

    function IndexOutOfBoundsError(
        uint256 index,
        uint256 length
    )
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            INDEX_OUT_OF_BOUNDS_ERROR_SELECTOR,
            index,
            length
        );
    }

    function SenderNotAuthorizedError(address sender)
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            SENDER_NOT_AUTHORIZED_ERROR_SELECTOR,
            sender
        );
    }

    function TargetAlreadyAuthorizedError(address target)
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            TARGET_ALREADY_AUTHORIZED_ERROR_SELECTOR,
            target
        );
    }

    function TargetNotAuthorizedError(address target)
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            TARGET_NOT_AUTHORIZED_ERROR_SELECTOR,
            target
        );
    }

    function ZeroCantBeAuthorizedError()
        internal
        pure
        returns (bytes memory)
    {
        return ZERO_CANT_BE_AUTHORIZED_ERROR_BYTES;
    }
}

File 14 of 58 : Ownable.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;

import "./interfaces/IOwnable.sol";
import "./LibOwnableRichErrors.sol";
import "./LibRichErrors.sol";


contract Ownable is
    IOwnable
{
    address public owner;

    constructor ()
        public
    {
        owner = msg.sender;
    }

    modifier onlyOwner() {
        _assertSenderIsOwner();
        _;
    }

    function transferOwnership(address newOwner)
        public
        onlyOwner
    {
        if (newOwner == address(0)) {
            LibRichErrors.rrevert(LibOwnableRichErrors.TransferOwnerToZeroError());
        } else {
            owner = newOwner;
            emit OwnershipTransferred(msg.sender, newOwner);
        }
    }

    function _assertSenderIsOwner()
        internal
        view
    {
        if (msg.sender != owner) {
            LibRichErrors.rrevert(LibOwnableRichErrors.OnlyOwnerError(
                msg.sender,
                owner
            ));
        }
    }
}

File 15 of 58 : LibOwnableRichErrors.sol
pragma solidity ^0.5.9;


library LibOwnableRichErrors {

    // bytes4(keccak256("OnlyOwnerError(address,address)"))
    bytes4 internal constant ONLY_OWNER_ERROR_SELECTOR =
        0x1de45ad1;

    // bytes4(keccak256("TransferOwnerToZeroError()"))
    bytes internal constant TRANSFER_OWNER_TO_ZERO_ERROR_BYTES =
        hex"e69edc3e";

    // solhint-disable func-name-mixedcase
    function OnlyOwnerError(
        address sender,
        address owner
    )
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            ONLY_OWNER_ERROR_SELECTOR,
            sender,
            owner
        );
    }

    function TransferOwnerToZeroError()
        internal
        pure
        returns (bytes memory)
    {
        return TRANSFER_OWNER_TO_ZERO_ERROR_BYTES;
    }
}

File 16 of 58 : MixinConstants.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;


contract MixinConstants {

    // 100% in parts-per-million.
    uint32 constant internal PPM_DENOMINATOR = 10**6;

    bytes32 constant internal NIL_POOL_ID = 0x0000000000000000000000000000000000000000000000000000000000000000;

    address constant internal NIL_ADDRESS = 0x0000000000000000000000000000000000000000;

    uint256 constant internal MIN_TOKEN_VALUE = 10**18;
}

File 17 of 58 : LibStakingRichErrors.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;

import "@0x/contracts-utils/contracts/src/LibRichErrors.sol";
import "../interfaces/IStructs.sol";


library LibStakingRichErrors {

    enum OperatorShareErrorCodes {
        OperatorShareTooLarge,
        CanOnlyDecreaseOperatorShare
    }

    enum InitializationErrorCodes {
        MixinSchedulerAlreadyInitialized,
        MixinParamsAlreadyInitialized
    }

    enum InvalidParamValueErrorCodes {
        InvalidCobbDouglasAlpha,
        InvalidRewardDelegatedStakeWeight,
        InvalidMaximumMakersInPool,
        InvalidMinimumPoolStake,
        InvalidEpochDuration
    }

    enum ExchangeManagerErrorCodes {
        ExchangeAlreadyRegistered,
        ExchangeNotRegistered
    }

    // bytes4(keccak256("OnlyCallableByExchangeError(address)"))
    bytes4 internal constant ONLY_CALLABLE_BY_EXCHANGE_ERROR_SELECTOR =
        0xb56d2df0;

    // bytes4(keccak256("ExchangeManagerError(uint8,address)"))
    bytes4 internal constant EXCHANGE_MANAGER_ERROR_SELECTOR =
        0xb9588e43;

    // bytes4(keccak256("InsufficientBalanceError(uint256,uint256)"))
    bytes4 internal constant INSUFFICIENT_BALANCE_ERROR_SELECTOR =
        0x84c8b7c9;

    // bytes4(keccak256("OnlyCallableByPoolOperatorError(address,bytes32)"))
    bytes4 internal constant ONLY_CALLABLE_BY_POOL_OPERATOR_ERROR_SELECTOR =
        0x82ded785;

    // bytes4(keccak256("BlockTimestampTooLowError(uint256,uint256)"))
    bytes4 internal constant BLOCK_TIMESTAMP_TOO_LOW_ERROR_SELECTOR =
        0xa6bcde47;

    // bytes4(keccak256("OnlyCallableByStakingContractError(address)"))
    bytes4 internal constant ONLY_CALLABLE_BY_STAKING_CONTRACT_ERROR_SELECTOR =
        0xca1d07a2;

    // bytes4(keccak256("OnlyCallableIfInCatastrophicFailureError()"))
    bytes internal constant ONLY_CALLABLE_IF_IN_CATASTROPHIC_FAILURE_ERROR =
        hex"3ef081cc";

    // bytes4(keccak256("OnlyCallableIfNotInCatastrophicFailureError()"))
    bytes internal constant ONLY_CALLABLE_IF_NOT_IN_CATASTROPHIC_FAILURE_ERROR =
        hex"7dd020ce";

    // bytes4(keccak256("OperatorShareError(uint8,bytes32,uint32)"))
    bytes4 internal constant OPERATOR_SHARE_ERROR_SELECTOR =
        0x22df9597;

    // bytes4(keccak256("PoolExistenceError(bytes32,bool)"))
    bytes4 internal constant POOL_EXISTENCE_ERROR_SELECTOR =
        0x9ae94f01;

    // bytes4(keccak256("ProxyDestinationCannotBeNilError()"))
    bytes internal constant PROXY_DESTINATION_CANNOT_BE_NIL_ERROR =
        hex"6eff8285";

    // bytes4(keccak256("InitializationError(uint8)"))
    bytes4 internal constant INITIALIZATION_ERROR_SELECTOR =
        0x0b02d773;

    // bytes4(keccak256("InvalidParamValueError(uint8)"))
    bytes4 internal constant INVALID_PARAM_VALUE_ERROR_SELECTOR =
        0xfc45bd11;

    // bytes4(keccak256("InvalidProtocolFeePaymentError(uint256,uint256)"))
    bytes4 internal constant INVALID_PROTOCOL_FEE_PAYMENT_ERROR_SELECTOR =
        0x31d7a505;

    // bytes4(keccak256("PreviousEpochNotFinalizedError(uint256,uint256)"))
    bytes4 internal constant PREVIOUS_EPOCH_NOT_FINALIZED_ERROR_SELECTOR =
        0x614b800a;

    // bytes4(keccak256("PoolNotFinalizedError(bytes32,uint256)"))
    bytes4 internal constant POOL_NOT_FINALIZED_ERROR_SELECTOR =
        0x5caa0b05;

    // solhint-disable func-name-mixedcase
    function OnlyCallableByExchangeError(
        address senderAddress
    )
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            ONLY_CALLABLE_BY_EXCHANGE_ERROR_SELECTOR,
            senderAddress
        );
    }

    function ExchangeManagerError(
        ExchangeManagerErrorCodes errorCodes,
        address exchangeAddress
    )
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            EXCHANGE_MANAGER_ERROR_SELECTOR,
            errorCodes,
            exchangeAddress
        );
    }

    function InsufficientBalanceError(
        uint256 amount,
        uint256 balance
    )
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            INSUFFICIENT_BALANCE_ERROR_SELECTOR,
            amount,
            balance
        );
    }

    function OnlyCallableByPoolOperatorError(
        address senderAddress,
        bytes32 poolId
    )
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            ONLY_CALLABLE_BY_POOL_OPERATOR_ERROR_SELECTOR,
            senderAddress,
            poolId
        );
    }

    function BlockTimestampTooLowError(
        uint256 epochEndTime,
        uint256 currentBlockTimestamp
    )
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            BLOCK_TIMESTAMP_TOO_LOW_ERROR_SELECTOR,
            epochEndTime,
            currentBlockTimestamp
        );
    }

    function OnlyCallableByStakingContractError(
        address senderAddress
    )
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            ONLY_CALLABLE_BY_STAKING_CONTRACT_ERROR_SELECTOR,
            senderAddress
        );
    }

    function OnlyCallableIfInCatastrophicFailureError()
        internal
        pure
        returns (bytes memory)
    {
        return ONLY_CALLABLE_IF_IN_CATASTROPHIC_FAILURE_ERROR;
    }

    function OnlyCallableIfNotInCatastrophicFailureError()
        internal
        pure
        returns (bytes memory)
    {
        return ONLY_CALLABLE_IF_NOT_IN_CATASTROPHIC_FAILURE_ERROR;
    }

    function OperatorShareError(
        OperatorShareErrorCodes errorCodes,
        bytes32 poolId,
        uint32 operatorShare
    )
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            OPERATOR_SHARE_ERROR_SELECTOR,
            errorCodes,
            poolId,
            operatorShare
        );
    }

    function PoolExistenceError(
        bytes32 poolId,
        bool alreadyExists
    )
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            POOL_EXISTENCE_ERROR_SELECTOR,
            poolId,
            alreadyExists
        );
    }

    function InvalidProtocolFeePaymentError(
        uint256 expectedProtocolFeePaid,
        uint256 actualProtocolFeePaid
    )
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            INVALID_PROTOCOL_FEE_PAYMENT_ERROR_SELECTOR,
            expectedProtocolFeePaid,
            actualProtocolFeePaid
        );
    }

    function InitializationError(InitializationErrorCodes code)
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            INITIALIZATION_ERROR_SELECTOR,
            uint8(code)
        );
    }

    function InvalidParamValueError(InvalidParamValueErrorCodes code)
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            INVALID_PARAM_VALUE_ERROR_SELECTOR,
            uint8(code)
        );
    }

    function ProxyDestinationCannotBeNilError()
        internal
        pure
        returns (bytes memory)
    {
        return PROXY_DESTINATION_CANNOT_BE_NIL_ERROR;
    }

    function PreviousEpochNotFinalizedError(
        uint256 unfinalizedEpoch,
        uint256 unfinalizedPoolsRemaining
    )
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            PREVIOUS_EPOCH_NOT_FINALIZED_ERROR_SELECTOR,
            unfinalizedEpoch,
            unfinalizedPoolsRemaining
        );
    }

    function PoolNotFinalizedError(
        bytes32 poolId,
        uint256 epoch
    )
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            POOL_NOT_FINALIZED_ERROR_SELECTOR,
            poolId,
            epoch
        );
    }
}

File 18 of 58 : IStakingEvents.sol
pragma solidity ^0.5.9;


interface IStakingEvents {

    /// @dev Emitted by MixinStake when ZRX is staked.
    /// @param staker of ZRX.
    /// @param amount of ZRX staked.
    event Stake(
        address indexed staker,
        uint256 amount
    );

    /// @dev Emitted by MixinStake when ZRX is unstaked.
    /// @param staker of ZRX.
    /// @param amount of ZRX unstaked.
    event Unstake(
        address indexed staker,
        uint256 amount
    );

    /// @dev Emitted by MixinStake when ZRX is unstaked.
    /// @param staker of ZRX.
    /// @param amount of ZRX unstaked.
    event MoveStake(
        address indexed staker,
        uint256 amount,
        uint8 fromStatus,
        bytes32 indexed fromPool,
        uint8 toStatus,
        bytes32 indexed toPool
    );

    /// @dev Emitted by MixinExchangeManager when an exchange is added.
    /// @param exchangeAddress Address of new exchange.
    event ExchangeAdded(
        address exchangeAddress
    );

    /// @dev Emitted by MixinExchangeManager when an exchange is removed.
    /// @param exchangeAddress Address of removed exchange.
    event ExchangeRemoved(
        address exchangeAddress
    );

    /// @dev Emitted by MixinExchangeFees when a pool starts earning rewards in an epoch.
    /// @param epoch The epoch in which the pool earned rewards.
    /// @param poolId The ID of the pool.
    event StakingPoolEarnedRewardsInEpoch(
        uint256 indexed epoch,
        bytes32 indexed poolId
    );

    /// @dev Emitted by MixinFinalizer when an epoch has ended.
    /// @param epoch The epoch that ended.
    /// @param numPoolsToFinalize Number of pools that earned rewards during `epoch` and must be finalized.
    /// @param rewardsAvailable Rewards available to all pools that earned rewards during `epoch`.
    /// @param totalWeightedStake Total weighted stake across all pools that earned rewards during `epoch`.
    /// @param totalFeesCollected Total fees collected across all pools that earned rewards during `epoch`.
    event EpochEnded(
        uint256 indexed epoch,
        uint256 numPoolsToFinalize,
        uint256 rewardsAvailable,
        uint256 totalFeesCollected,
        uint256 totalWeightedStake
    );

    /// @dev Emitted by MixinFinalizer when an epoch is fully finalized.
    /// @param epoch The epoch being finalized.
    /// @param rewardsPaid Total amount of rewards paid out.
    /// @param rewardsRemaining Rewards left over.
    event EpochFinalized(
        uint256 indexed epoch,
        uint256 rewardsPaid,
        uint256 rewardsRemaining
    );

    /// @dev Emitted by MixinFinalizer when rewards are paid out to a pool.
    /// @param epoch The epoch when the rewards were paid out.
    /// @param poolId The pool's ID.
    /// @param operatorReward Amount of reward paid to pool operator.
    /// @param membersReward Amount of reward paid to pool members.
    event RewardsPaid(
        uint256 indexed epoch,
        bytes32 indexed poolId,
        uint256 operatorReward,
        uint256 membersReward
    );

    /// @dev Emitted whenever staking parameters are changed via the `setParams()` function.
    /// @param epochDurationInSeconds Minimum seconds between epochs.
    /// @param rewardDelegatedStakeWeight How much delegated stake is weighted vs operator stake, in ppm.
    /// @param minimumPoolStake Minimum amount of stake required in a pool to collect rewards.
    /// @param cobbDouglasAlphaNumerator Numerator for cobb douglas alpha factor.
    /// @param cobbDouglasAlphaDenominator Denominator for cobb douglas alpha factor.
    event ParamsSet(
        uint256 epochDurationInSeconds,
        uint32 rewardDelegatedStakeWeight,
        uint256 minimumPoolStake,
        uint256 cobbDouglasAlphaNumerator,
        uint256 cobbDouglasAlphaDenominator
    );

    /// @dev Emitted by MixinStakingPool when a new pool is created.
    /// @param poolId Unique id generated for pool.
    /// @param operator The operator (creator) of pool.
    /// @param operatorShare The share of rewards given to the operator, in ppm.
    event StakingPoolCreated(
        bytes32 poolId,
        address operator,
        uint32 operatorShare
    );

    /// @dev Emitted by MixinStakingPool when a maker sets their pool.
    /// @param makerAddress Adress of maker added to pool.
    /// @param poolId Unique id of pool.
    event MakerStakingPoolSet(
        address indexed makerAddress,
        bytes32 indexed poolId
    );

    /// @dev Emitted when a staking pool's operator share is decreased.
    /// @param poolId Unique Id of pool.
    /// @param oldOperatorShare Previous share of rewards owned by operator.
    /// @param newOperatorShare Newly decreased share of rewards owned by operator.
    event OperatorShareDecreased(
        bytes32 indexed poolId,
        uint32 oldOperatorShare,
        uint32 newOperatorShare
    );
}

File 19 of 58 : IStakingProxy.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;
pragma experimental ABIEncoderV2;

import "./IStructs.sol";


contract IStakingProxy {

    /// @dev Emitted by StakingProxy when a staking contract is attached.
    /// @param newStakingContractAddress Address of newly attached staking contract.
    event StakingContractAttachedToProxy(
        address newStakingContractAddress
    );

    /// @dev Emitted by StakingProxy when a staking contract is detached.
    event StakingContractDetachedFromProxy();

    /// @dev Attach a staking contract; future calls will be delegated to the staking contract.
    /// Note that this is callable only by an authorized address.
    /// @param _stakingContract Address of staking contract.
    function attachStakingContract(address _stakingContract)
        external;

    /// @dev Detach the current staking contract.
    /// Note that this is callable only by an authorized address.
    function detachStakingContract()
        external;

    /// @dev Asserts that an epoch is between 5 and 30 days long.
    //       Asserts that 0 < cobb douglas alpha value <= 1.
    //       Asserts that a stake weight is <= 100%.
    //       Asserts that pools allow >= 1 maker.
    //       Asserts that all addresses are initialized.
    function assertValidStorageParams()
        external
        view;
}

File 20 of 58 : MixinStake.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;
pragma experimental ABIEncoderV2;

import "@0x/contracts-utils/contracts/src/LibSafeMath.sol";
import "../staking_pools/MixinStakingPool.sol";
import "../libs/LibStakingRichErrors.sol";


contract MixinStake is
    MixinStakingPool
{
    using LibSafeMath for uint256;

    /// @dev Stake ZRX tokens. Tokens are deposited into the ZRX Vault.
    ///      Unstake to retrieve the ZRX. Stake is in the 'Active' status.
    /// @param amount of ZRX to stake.
    function stake(uint256 amount)
        external
    {
        address staker = msg.sender;

        // deposit equivalent amount of ZRX into vault
        getZrxVault().depositFrom(staker, amount);

        // mint stake
        _increaseCurrentAndNextBalance(
            _ownerStakeByStatus[uint8(IStructs.StakeStatus.UNDELEGATED)][staker],
            amount
        );

        // notify
        emit Stake(
            staker,
            amount
        );
    }

    /// @dev Unstake. Tokens are withdrawn from the ZRX Vault and returned to
    ///      the staker. Stake must be in the 'undelegated' status in both the
    ///      current and next epoch in order to be unstaked.
    /// @param amount of ZRX to unstake.
    function unstake(uint256 amount)
        external
    {
        address staker = msg.sender;

        IStructs.StoredBalance memory undelegatedBalance =
            _loadCurrentBalance(_ownerStakeByStatus[uint8(IStructs.StakeStatus.UNDELEGATED)][staker]);

        // stake must be undelegated in current and next epoch to be withdrawn
        uint256 currentWithdrawableStake = LibSafeMath.min256(
            undelegatedBalance.currentEpochBalance,
            undelegatedBalance.nextEpochBalance
        );

        if (amount > currentWithdrawableStake) {
            LibRichErrors.rrevert(
                LibStakingRichErrors.InsufficientBalanceError(
                    amount,
                    currentWithdrawableStake
                )
            );
        }

        // burn undelegated stake
        _decreaseCurrentAndNextBalance(
            _ownerStakeByStatus[uint8(IStructs.StakeStatus.UNDELEGATED)][staker],
            amount
        );

        // withdraw equivalent amount of ZRX from vault
        getZrxVault().withdrawFrom(staker, amount);

        // emit stake event
        emit Unstake(
            staker,
            amount
        );
    }

    /// @dev Moves stake between statuses: 'undelegated' or 'delegated'.
    ///      Delegated stake can also be moved between pools.
    ///      This change comes into effect next epoch.
    /// @param from status to move stake out of.
    /// @param to status to move stake into.
    /// @param amount of stake to move.
    function moveStake(
        IStructs.StakeInfo calldata from,
        IStructs.StakeInfo calldata to,
        uint256 amount
    )
        external
    {
        address staker = msg.sender;

        // Sanity check: no-op if no stake is being moved.
        if (amount == 0) {
            return;
        }

        // Sanity check: no-op if moving stake from undelegated to undelegated.
        if (from.status == IStructs.StakeStatus.UNDELEGATED &&
            to.status == IStructs.StakeStatus.UNDELEGATED) {
            return;
        }

        // handle delegation
        if (from.status == IStructs.StakeStatus.DELEGATED) {
            _undelegateStake(
                from.poolId,
                staker,
                amount
            );
        }

        if (to.status == IStructs.StakeStatus.DELEGATED) {
            _delegateStake(
                to.poolId,
                staker,
                amount
            );
        }

        // execute move
        IStructs.StoredBalance storage fromPtr = _ownerStakeByStatus[uint8(from.status)][staker];
        IStructs.StoredBalance storage toPtr = _ownerStakeByStatus[uint8(to.status)][staker];
        _moveStake(
            fromPtr,
            toPtr,
            amount
        );

        // notify
        emit MoveStake(
            staker,
            amount,
            uint8(from.status),
            from.poolId,
            uint8(to.status),
            to.poolId
        );
    }

    /// @dev Delegates a owners stake to a staking pool.
    /// @param poolId Id of pool to delegate to.
    /// @param staker Owner who wants to delegate.
    /// @param amount Amount of stake to delegate.
    function _delegateStake(
        bytes32 poolId,
        address staker,
        uint256 amount
    )
        private
    {
        // Sanity check the pool we're delegating to exists.
        _assertStakingPoolExists(poolId);

        _withdrawAndSyncDelegatorRewards(
            poolId,
            staker
        );

        // Increase how much stake the staker has delegated to the input pool.
        _increaseNextBalance(
            _delegatedStakeToPoolByOwner[staker][poolId],
            amount
        );

        // Increase how much stake has been delegated to pool.
        _increaseNextBalance(
            _delegatedStakeByPoolId[poolId],
            amount
        );

        // Increase next balance of global delegated stake.
        _increaseNextBalance(
            _globalStakeByStatus[uint8(IStructs.StakeStatus.DELEGATED)],
            amount
        );
    }

    /// @dev Un-Delegates a owners stake from a staking pool.
    /// @param poolId Id of pool to un-delegate from.
    /// @param staker Owner who wants to un-delegate.
    /// @param amount Amount of stake to un-delegate.
    function _undelegateStake(
        bytes32 poolId,
        address staker,
        uint256 amount
    )
        private
    {
        // sanity check the pool we're undelegating from exists
        _assertStakingPoolExists(poolId);

        _withdrawAndSyncDelegatorRewards(
            poolId,
            staker
        );

        // Decrease how much stake the staker has delegated to the input pool.
        _decreaseNextBalance(
            _delegatedStakeToPoolByOwner[staker][poolId],
            amount
        );

        // Decrease how much stake has been delegated to pool.
        _decreaseNextBalance(
            _delegatedStakeByPoolId[poolId],
            amount
        );

        // Decrease next balance of global delegated stake (aggregated across all stakers).
        _decreaseNextBalance(
            _globalStakeByStatus[uint8(IStructs.StakeStatus.DELEGATED)],
            amount
        );
    }
}

File 21 of 58 : LibSafeMath.sol
pragma solidity ^0.5.9;

import "./LibRichErrors.sol";
import "./LibSafeMathRichErrors.sol";


library LibSafeMath {

    function safeMul(uint256 a, uint256 b)
        internal
        pure
        returns (uint256)
    {
        if (a == 0) {
            return 0;
        }
        uint256 c = a * b;
        if (c / a != b) {
            LibRichErrors.rrevert(LibSafeMathRichErrors.Uint256BinOpError(
                LibSafeMathRichErrors.BinOpErrorCodes.MULTIPLICATION_OVERFLOW,
                a,
                b
            ));
        }
        return c;
    }

    function safeDiv(uint256 a, uint256 b)
        internal
        pure
        returns (uint256)
    {
        if (b == 0) {
            LibRichErrors.rrevert(LibSafeMathRichErrors.Uint256BinOpError(
                LibSafeMathRichErrors.BinOpErrorCodes.DIVISION_BY_ZERO,
                a,
                b
            ));
        }
        uint256 c = a / b;
        return c;
    }

    function safeSub(uint256 a, uint256 b)
        internal
        pure
        returns (uint256)
    {
        if (b > a) {
            LibRichErrors.rrevert(LibSafeMathRichErrors.Uint256BinOpError(
                LibSafeMathRichErrors.BinOpErrorCodes.SUBTRACTION_UNDERFLOW,
                a,
                b
            ));
        }
        return a - b;
    }

    function safeAdd(uint256 a, uint256 b)
        internal
        pure
        returns (uint256)
    {
        uint256 c = a + b;
        if (c < a) {
            LibRichErrors.rrevert(LibSafeMathRichErrors.Uint256BinOpError(
                LibSafeMathRichErrors.BinOpErrorCodes.ADDITION_OVERFLOW,
                a,
                b
            ));
        }
        return c;
    }

    function max256(uint256 a, uint256 b)
        internal
        pure
        returns (uint256)
    {
        return a >= b ? a : b;
    }

    function min256(uint256 a, uint256 b)
        internal
        pure
        returns (uint256)
    {
        return a < b ? a : b;
    }
}

File 22 of 58 : LibSafeMathRichErrors.sol
pragma solidity ^0.5.9;


library LibSafeMathRichErrors {

    // bytes4(keccak256("Uint256BinOpError(uint8,uint256,uint256)"))
    bytes4 internal constant UINT256_BINOP_ERROR_SELECTOR =
        0xe946c1bb;

    // bytes4(keccak256("Uint256DowncastError(uint8,uint256)"))
    bytes4 internal constant UINT256_DOWNCAST_ERROR_SELECTOR =
        0xc996af7b;

    enum BinOpErrorCodes {
        ADDITION_OVERFLOW,
        MULTIPLICATION_OVERFLOW,
        SUBTRACTION_UNDERFLOW,
        DIVISION_BY_ZERO
    }

    enum DowncastErrorCodes {
        VALUE_TOO_LARGE_TO_DOWNCAST_TO_UINT32,
        VALUE_TOO_LARGE_TO_DOWNCAST_TO_UINT64,
        VALUE_TOO_LARGE_TO_DOWNCAST_TO_UINT96
    }

    // solhint-disable func-name-mixedcase
    function Uint256BinOpError(
        BinOpErrorCodes errorCode,
        uint256 a,
        uint256 b
    )
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            UINT256_BINOP_ERROR_SELECTOR,
            errorCode,
            a,
            b
        );
    }

    function Uint256DowncastError(
        DowncastErrorCodes errorCode,
        uint256 a
    )
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            UINT256_DOWNCAST_ERROR_SELECTOR,
            errorCode,
            a
        );
    }
}

File 23 of 58 : MixinStakingPool.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;
pragma experimental ABIEncoderV2;

import "@0x/contracts-utils/contracts/src/LibRichErrors.sol";
import "@0x/contracts-utils/contracts/src/LibSafeMath.sol";
import "../libs/LibStakingRichErrors.sol";
import "../interfaces/IStructs.sol";
import "../sys/MixinAbstract.sol";
import "./MixinStakingPoolRewards.sol";


contract MixinStakingPool is
    MixinAbstract,
    MixinStakingPoolRewards
{
    using LibSafeMath for uint256;
    using LibSafeDowncast for uint256;

    /// @dev Asserts that the sender is the operator of the input pool.
    /// @param poolId Pool sender must be operator of.
    modifier onlyStakingPoolOperator(bytes32 poolId) {
        _assertSenderIsPoolOperator(poolId);
        _;
    }

    /// @dev Create a new staking pool. The sender will be the operator of this pool.
    /// Note that an operator must be payable.
    /// @param operatorShare Portion of rewards owned by the operator, in ppm.
    /// @param addOperatorAsMaker Adds operator to the created pool as a maker for convenience iff true.
    /// @return poolId The unique pool id generated for this pool.
    function createStakingPool(uint32 operatorShare, bool addOperatorAsMaker)
        external
        returns (bytes32 poolId)
    {
        // note that an operator must be payable
        address operator = msg.sender;

        // compute unique id for this pool
        poolId = lastPoolId = bytes32(uint256(lastPoolId).safeAdd(1));

        // sanity check on operator share
        _assertNewOperatorShare(
            poolId,
            PPM_DENOMINATOR,    // max operator share
            operatorShare
        );

        // create and store pool
        IStructs.Pool memory pool = IStructs.Pool({
            operator: operator,
            operatorShare: operatorShare
        });
        _poolById[poolId] = pool;

        // Staking pool has been created
        emit StakingPoolCreated(poolId, operator, operatorShare);

        if (addOperatorAsMaker) {
            joinStakingPoolAsMaker(poolId);
        }

        return poolId;
    }

    /// @dev Decreases the operator share for the given pool (i.e. increases pool rewards for members).
    /// @param poolId Unique Id of pool.
    /// @param newOperatorShare The newly decreased percentage of any rewards owned by the operator.
    function decreaseStakingPoolOperatorShare(bytes32 poolId, uint32 newOperatorShare)
        external
        onlyStakingPoolOperator(poolId)
    {
        // load pool and assert that we can decrease
        uint32 currentOperatorShare = _poolById[poolId].operatorShare;
        _assertNewOperatorShare(
            poolId,
            currentOperatorShare,
            newOperatorShare
        );

        // decrease operator share
        _poolById[poolId].operatorShare = newOperatorShare;
        emit OperatorShareDecreased(
            poolId,
            currentOperatorShare,
            newOperatorShare
        );
    }

    /// @dev Allows caller to join a staking pool as a maker.
    /// @param poolId Unique id of pool.
    function joinStakingPoolAsMaker(bytes32 poolId)
        public
    {
        address maker = msg.sender;
        poolIdByMaker[maker] = poolId;
        emit MakerStakingPoolSet(
            maker,
            poolId
        );
    }

    /// @dev Returns a staking pool
    /// @param poolId Unique id of pool.
    function getStakingPool(bytes32 poolId)
        public
        view
        returns (IStructs.Pool memory)
    {
        return _poolById[poolId];
    }

    /// @dev Reverts iff a staking pool does not exist.
    /// @param poolId Unique id of pool.
    function _assertStakingPoolExists(bytes32 poolId)
        internal
        view
    {
        if (_poolById[poolId].operator == NIL_ADDRESS) {
            // we use the pool's operator as a proxy for its existence
            LibRichErrors.rrevert(
                LibStakingRichErrors.PoolExistenceError(
                    poolId,
                    false
                )
            );
        }
    }

    /// @dev Reverts iff the new operator share is invalid.
    /// @param poolId Unique id of pool.
    /// @param currentOperatorShare Current operator share.
    /// @param newOperatorShare New operator share.
    function _assertNewOperatorShare(
        bytes32 poolId,
        uint32 currentOperatorShare,
        uint32 newOperatorShare
    )
        private
        pure
    {
        // sanity checks
        if (newOperatorShare > PPM_DENOMINATOR) {
            // operator share must be a valid fraction
            LibRichErrors.rrevert(LibStakingRichErrors.OperatorShareError(
                LibStakingRichErrors.OperatorShareErrorCodes.OperatorShareTooLarge,
                poolId,
                newOperatorShare
            ));
        } else if (newOperatorShare > currentOperatorShare) {
            // new share must be less than or equal to the current share
            LibRichErrors.rrevert(LibStakingRichErrors.OperatorShareError(
                LibStakingRichErrors.OperatorShareErrorCodes.CanOnlyDecreaseOperatorShare,
                poolId,
                newOperatorShare
            ));
        }
    }

    /// @dev Asserts that the sender is the operator of the input pool.
    /// @param poolId Pool sender must be operator of.
    function _assertSenderIsPoolOperator(bytes32 poolId)
        private
        view
    {
        address operator = _poolById[poolId].operator;
        if (msg.sender != operator) {
            LibRichErrors.rrevert(
                LibStakingRichErrors.OnlyCallableByPoolOperatorError(
                    msg.sender,
                    poolId
                )
            );
        }
    }
}

File 24 of 58 : MixinAbstract.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;
pragma experimental ABIEncoderV2;


/// @dev Exposes some internal functions from various contracts to avoid
///      cyclical dependencies.
contract MixinAbstract {

    /// @dev Computes the reward owed to a pool during finalization.
    ///      Does nothing if the pool is already finalized.
    /// @param poolId The pool's ID.
    /// @return totalReward The total reward owed to a pool.
    /// @return membersStake The total stake for all non-operator members in
    ///         this pool.
    function _getUnfinalizedPoolRewards(bytes32 poolId)
        internal
        view
        returns (
            uint256 totalReward,
            uint256 membersStake
        );

    /// @dev Asserts that a pool has been finalized last epoch.
    /// @param poolId The id of the pool that should have been finalized.
    function _assertPoolFinalizedLastEpoch(bytes32 poolId)
        internal
        view;
}

File 25 of 58 : MixinStakingPoolRewards.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;
pragma experimental ABIEncoderV2;

import "@0x/contracts-exchange-libs/contracts/src/LibMath.sol";
import "@0x/contracts-utils/contracts/src/LibSafeMath.sol";
import "./MixinCumulativeRewards.sol";
import "../sys/MixinAbstract.sol";


contract MixinStakingPoolRewards is
    MixinAbstract,
    MixinCumulativeRewards
{
    using LibSafeMath for uint256;

    /// @dev Withdraws the caller's WETH rewards that have accumulated
    ///      until the last epoch.
    /// @param poolId Unique id of pool.
    function withdrawDelegatorRewards(bytes32 poolId)
        external
    {
        _withdrawAndSyncDelegatorRewards(poolId, msg.sender);
    }

    /// @dev Computes the reward balance in ETH of the operator of a pool.
    /// @param poolId Unique id of pool.
    /// @return totalReward Balance in ETH.
    function computeRewardBalanceOfOperator(bytes32 poolId)
        external
        view
        returns (uint256 reward)
    {
        // Because operator rewards are immediately withdrawn as WETH
        // on finalization, the only factor in this function are unfinalized
        // rewards.
        IStructs.Pool memory pool = _poolById[poolId];
        // Get any unfinalized rewards.
        (uint256 unfinalizedTotalRewards, uint256 unfinalizedMembersStake) =
            _getUnfinalizedPoolRewards(poolId);

        // Get the operators' portion.
        (reward,) = _computePoolRewardsSplit(
            pool.operatorShare,
            unfinalizedTotalRewards,
            unfinalizedMembersStake
        );
        return reward;
    }

    /// @dev Computes the reward balance in ETH of a specific member of a pool.
    /// @param poolId Unique id of pool.
    /// @param member The member of the pool.
    /// @return totalReward Balance in ETH.
    function computeRewardBalanceOfDelegator(bytes32 poolId, address member)
        external
        view
        returns (uint256 reward)
    {
        IStructs.Pool memory pool = _poolById[poolId];
        // Get any unfinalized rewards.
        (uint256 unfinalizedTotalRewards, uint256 unfinalizedMembersStake) =
            _getUnfinalizedPoolRewards(poolId);

        // Get the members' portion.
        (, uint256 unfinalizedMembersReward) = _computePoolRewardsSplit(
            pool.operatorShare,
            unfinalizedTotalRewards,
            unfinalizedMembersStake
        );
        return _computeDelegatorReward(
            poolId,
            member,
            unfinalizedMembersReward,
            unfinalizedMembersStake
        );
    }

    /// @dev Syncs rewards for a delegator. This includes withdrawing rewards
    ///      rewards and adding/removing dependencies on cumulative rewards.
    /// @param poolId Unique id of pool.
    /// @param member of the pool.
    function _withdrawAndSyncDelegatorRewards(
        bytes32 poolId,
        address member
    )
        internal
    {
        // Ensure the pool is finalized.
        _assertPoolFinalizedLastEpoch(poolId);

        // Compute balance owed to delegator
        uint256 balance = _computeDelegatorReward(
            poolId,
            member,
            // No unfinalized values because we ensured the pool is already
            // finalized.
            0,
            0
        );

        // Sync the delegated stake balance. This will ensure future calls of
        // `_computeDelegatorReward` during this epoch will return 0, 
        // preventing a delegator from withdrawing more than once an epoch.
        _delegatedStakeToPoolByOwner[member][poolId] =
            _loadCurrentBalance(_delegatedStakeToPoolByOwner[member][poolId]);

        // Withdraw non-0 balance
        if (balance != 0) {
            // Decrease the balance of the pool
            _decreasePoolRewards(poolId, balance);

            // Withdraw the member's WETH balance
            getWethContract().transfer(member, balance);
        }

        // Ensure a cumulative reward entry exists for this epoch,
        // copying the previous epoch's CR if one doesn't exist already.
        _updateCumulativeReward(poolId);
    }

    /// @dev Handles a pool's reward at the current epoch.
    ///      This will split the reward between the operator and members,
    ///      depositing them into their respective vaults, and update the
    ///      accounting needed to allow members to withdraw their individual
    ///      rewards.
    /// @param poolId Unique Id of pool.
    /// @param reward received by the pool.
    /// @param membersStake the amount of non-operator delegated stake that
    ///        will split the  reward.
    /// @return operatorReward Portion of `reward` given to the pool operator.
    /// @return membersReward Portion of `reward` given to the pool members.
    function _syncPoolRewards(
        bytes32 poolId,
        uint256 reward,
        uint256 membersStake
    )
        internal
        returns (uint256 operatorReward, uint256 membersReward)
    {
        IStructs.Pool memory pool = _poolById[poolId];

        // Split the reward between operator and members
        (operatorReward, membersReward) = _computePoolRewardsSplit(
            pool.operatorShare,
            reward,
            membersStake
        );

        if (operatorReward > 0) {
            // Transfer the operator's weth reward to the operator
            getWethContract().transfer(pool.operator, operatorReward);
        }

        if (membersReward > 0) {
            // Increase the balance of the pool
            _increasePoolRewards(poolId, membersReward);
            // Create a cumulative reward entry at the current epoch.
            _addCumulativeReward(poolId, membersReward, membersStake);
        }

        return (operatorReward, membersReward);
    }

    /// @dev Compute the split of a pool reward between the operator and members
    ///      based on the `operatorShare` and `membersStake`.
    /// @param operatorShare The fraction of rewards owed to the operator,
    ///        in PPM.
    /// @param totalReward The pool reward.
    /// @param membersStake The amount of member (non-operator) stake delegated
    ///        to the pool in the epoch the rewards were earned.
    /// @return operatorReward Portion of `totalReward` given to the pool operator.
    /// @return membersReward Portion of `totalReward` given to the pool members.
    function _computePoolRewardsSplit(
        uint32 operatorShare,
        uint256 totalReward,
        uint256 membersStake
    )
        internal
        pure
        returns (uint256 operatorReward, uint256 membersReward)
    {
        if (membersStake == 0) {
            operatorReward = totalReward;
        } else {
            operatorReward = LibMath.getPartialAmountCeil(
                uint256(operatorShare),
                PPM_DENOMINATOR,
                totalReward
            );
            membersReward = totalReward.safeSub(operatorReward);
        }
        return (operatorReward, membersReward);
    }

    /// @dev Computes the reward balance in ETH of a specific member of a pool.
    /// @param poolId Unique id of pool.
    /// @param member of the pool.
    /// @param unfinalizedMembersReward Unfinalized total members reward (if any).
    /// @param unfinalizedMembersStake Unfinalized total members stake (if any).
    /// @return reward Balance in WETH.
    function _computeDelegatorReward(
        bytes32 poolId,
        address member,
        uint256 unfinalizedMembersReward,
        uint256 unfinalizedMembersStake
    )
        private
        view
        returns (uint256 reward)
    {
        uint256 currentEpoch_ = currentEpoch;
        IStructs.StoredBalance memory delegatedStake = _delegatedStakeToPoolByOwner[member][poolId];

        // There can be no rewards if the last epoch when stake was stored is
        // equal to the current epoch, because all prior rewards, including
        // rewards finalized this epoch have been claimed.
        if (delegatedStake.currentEpoch == currentEpoch_) {
            return 0;
        }

        // We account for rewards over 3 intervals, below.

        // 1/3 Unfinalized rewards earned in `currentEpoch - 1`.
        reward = _computeUnfinalizedDelegatorReward(
            delegatedStake,
            currentEpoch_,
            unfinalizedMembersReward,
            unfinalizedMembersStake
        );

        // 2/3 Finalized rewards earned in epochs [`delegatedStake.currentEpoch + 1` .. `currentEpoch - 1`]
        uint256 delegatedStakeNextEpoch = uint256(delegatedStake.currentEpoch).safeAdd(1);
        reward = reward.safeAdd(
            _computeMemberRewardOverInterval(
                poolId,
                delegatedStake.currentEpochBalance,
                delegatedStake.currentEpoch,
                delegatedStakeNextEpoch
            )
        );

        // 3/3 Finalized rewards earned in epoch `delegatedStake.currentEpoch`.
        reward = reward.safeAdd(
            _computeMemberRewardOverInterval(
                poolId,
                delegatedStake.nextEpochBalance,
                delegatedStakeNextEpoch,
                currentEpoch_
            )
        );

        return reward;
    }

    /// @dev Computes the unfinalized rewards earned by a delegator in the last epoch.
    /// @param delegatedStake Amount of stake delegated to pool by a specific staker
    /// @param currentEpoch_ The epoch in which this call is executing
    /// @param unfinalizedMembersReward Unfinalized total members reward (if any).
    /// @param unfinalizedMembersStake Unfinalized total members stake (if any).
    /// @return reward Balance in WETH.
    function _computeUnfinalizedDelegatorReward(
        IStructs.StoredBalance memory delegatedStake,
        uint256 currentEpoch_,
        uint256 unfinalizedMembersReward,
        uint256 unfinalizedMembersStake
    )
        private
        pure
        returns (uint256)
    {
        // If there are unfinalized rewards this epoch, compute the member's
        // share.
        if (unfinalizedMembersReward == 0 || unfinalizedMembersStake == 0) {
            return 0;
        }

        // Unfinalized rewards are always earned from stake in
        // the prior epoch so we want the stake at `currentEpoch_-1`.
        uint256 unfinalizedStakeBalance = delegatedStake.currentEpoch >= currentEpoch_.safeSub(1) ?
            delegatedStake.currentEpochBalance :
            delegatedStake.nextEpochBalance;

        // Sanity check to save gas on computation
        if (unfinalizedStakeBalance == 0) {
            return 0;
        }

        // Compute unfinalized reward
        return LibMath.getPartialAmountFloor(
            unfinalizedMembersReward,
            unfinalizedMembersStake,
            unfinalizedStakeBalance
        );
    }

    /// @dev Increases rewards for a pool.
    /// @param poolId Unique id of pool.
    /// @param amount Amount to increment rewards by.
    function _increasePoolRewards(bytes32 poolId, uint256 amount)
        private
    {
        rewardsByPoolId[poolId] = rewardsByPoolId[poolId].safeAdd(amount);
        wethReservedForPoolRewards = wethReservedForPoolRewards.safeAdd(amount);
    }

    /// @dev Decreases rewards for a pool.
    /// @param poolId Unique id of pool.
    /// @param amount Amount to decrement rewards by.
    function _decreasePoolRewards(bytes32 poolId, uint256 amount)
        private
    {
        rewardsByPoolId[poolId] = rewardsByPoolId[poolId].safeSub(amount);
        wethReservedForPoolRewards = wethReservedForPoolRewards.safeSub(amount);
    }
}

File 26 of 58 : LibMath.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;

import "@0x/contracts-utils/contracts/src/LibSafeMath.sol";
import "@0x/contracts-utils/contracts/src/LibRichErrors.sol";
import "./LibMathRichErrors.sol";


library LibMath {

    using LibSafeMath for uint256;

    /// @dev Calculates partial value given a numerator and denominator rounded down.
    ///      Reverts if rounding error is >= 0.1%
    /// @param numerator Numerator.
    /// @param denominator Denominator.
    /// @param target Value to calculate partial of.
    /// @return Partial value of target rounded down.
    function safeGetPartialAmountFloor(
        uint256 numerator,
        uint256 denominator,
        uint256 target
    )
        internal
        pure
        returns (uint256 partialAmount)
    {
        if (isRoundingErrorFloor(
                numerator,
                denominator,
                target
        )) {
            LibRichErrors.rrevert(LibMathRichErrors.RoundingError(
                numerator,
                denominator,
                target
            ));
        }

        partialAmount = numerator.safeMul(target).safeDiv(denominator);
        return partialAmount;
    }

    /// @dev Calculates partial value given a numerator and denominator rounded down.
    ///      Reverts if rounding error is >= 0.1%
    /// @param numerator Numerator.
    /// @param denominator Denominator.
    /// @param target Value to calculate partial of.
    /// @return Partial value of target rounded up.
    function safeGetPartialAmountCeil(
        uint256 numerator,
        uint256 denominator,
        uint256 target
    )
        internal
        pure
        returns (uint256 partialAmount)
    {
        if (isRoundingErrorCeil(
                numerator,
                denominator,
                target
        )) {
            LibRichErrors.rrevert(LibMathRichErrors.RoundingError(
                numerator,
                denominator,
                target
            ));
        }

        // safeDiv computes `floor(a / b)`. We use the identity (a, b integer):
        //       ceil(a / b) = floor((a + b - 1) / b)
        // To implement `ceil(a / b)` using safeDiv.
        partialAmount = numerator.safeMul(target)
            .safeAdd(denominator.safeSub(1))
            .safeDiv(denominator);

        return partialAmount;
    }

    /// @dev Calculates partial value given a numerator and denominator rounded down.
    /// @param numerator Numerator.
    /// @param denominator Denominator.
    /// @param target Value to calculate partial of.
    /// @return Partial value of target rounded down.
    function getPartialAmountFloor(
        uint256 numerator,
        uint256 denominator,
        uint256 target
    )
        internal
        pure
        returns (uint256 partialAmount)
    {
        partialAmount = numerator.safeMul(target).safeDiv(denominator);
        return partialAmount;
    }

    /// @dev Calculates partial value given a numerator and denominator rounded down.
    /// @param numerator Numerator.
    /// @param denominator Denominator.
    /// @param target Value to calculate partial of.
    /// @return Partial value of target rounded up.
    function getPartialAmountCeil(
        uint256 numerator,
        uint256 denominator,
        uint256 target
    )
        internal
        pure
        returns (uint256 partialAmount)
    {
        // safeDiv computes `floor(a / b)`. We use the identity (a, b integer):
        //       ceil(a / b) = floor((a + b - 1) / b)
        // To implement `ceil(a / b)` using safeDiv.
        partialAmount = numerator.safeMul(target)
            .safeAdd(denominator.safeSub(1))
            .safeDiv(denominator);

        return partialAmount;
    }

    /// @dev Checks if rounding error >= 0.1% when rounding down.
    /// @param numerator Numerator.
    /// @param denominator Denominator.
    /// @param target Value to multiply with numerator/denominator.
    /// @return Rounding error is present.
    function isRoundingErrorFloor(
        uint256 numerator,
        uint256 denominator,
        uint256 target
    )
        internal
        pure
        returns (bool isError)
    {
        if (denominator == 0) {
            LibRichErrors.rrevert(LibMathRichErrors.DivisionByZeroError());
        }

        // The absolute rounding error is the difference between the rounded
        // value and the ideal value. The relative rounding error is the
        // absolute rounding error divided by the absolute value of the
        // ideal value. This is undefined when the ideal value is zero.
        //
        // The ideal value is `numerator * target / denominator`.
        // Let's call `numerator * target % denominator` the remainder.
        // The absolute error is `remainder / denominator`.
        //
        // When the ideal value is zero, we require the absolute error to
        // be zero. Fortunately, this is always the case. The ideal value is
        // zero iff `numerator == 0` and/or `target == 0`. In this case the
        // remainder and absolute error are also zero.
        if (target == 0 || numerator == 0) {
            return false;
        }

        // Otherwise, we want the relative rounding error to be strictly
        // less than 0.1%.
        // The relative error is `remainder / (numerator * target)`.
        // We want the relative error less than 1 / 1000:
        //        remainder / (numerator * denominator)  <  1 / 1000
        // or equivalently:
        //        1000 * remainder  <  numerator * target
        // so we have a rounding error iff:
        //        1000 * remainder  >=  numerator * target
        uint256 remainder = mulmod(
            target,
            numerator,
            denominator
        );
        isError = remainder.safeMul(1000) >= numerator.safeMul(target);
        return isError;
    }

    /// @dev Checks if rounding error >= 0.1% when rounding up.
    /// @param numerator Numerator.
    /// @param denominator Denominator.
    /// @param target Value to multiply with numerator/denominator.
    /// @return Rounding error is present.
    function isRoundingErrorCeil(
        uint256 numerator,
        uint256 denominator,
        uint256 target
    )
        internal
        pure
        returns (bool isError)
    {
        if (denominator == 0) {
            LibRichErrors.rrevert(LibMathRichErrors.DivisionByZeroError());
        }

        // See the comments in `isRoundingError`.
        if (target == 0 || numerator == 0) {
            // When either is zero, the ideal value and rounded value are zero
            // and there is no rounding error. (Although the relative error
            // is undefined.)
            return false;
        }
        // Compute remainder as before
        uint256 remainder = mulmod(
            target,
            numerator,
            denominator
        );
        remainder = denominator.safeSub(remainder) % denominator;
        isError = remainder.safeMul(1000) >= numerator.safeMul(target);
        return isError;
    }
}

File 27 of 58 : LibMathRichErrors.sol
pragma solidity ^0.5.9;


library LibMathRichErrors {

    // bytes4(keccak256("DivisionByZeroError()"))
    bytes internal constant DIVISION_BY_ZERO_ERROR =
        hex"a791837c";

    // bytes4(keccak256("RoundingError(uint256,uint256,uint256)"))
    bytes4 internal constant ROUNDING_ERROR_SELECTOR =
        0x339f3de2;

    // solhint-disable func-name-mixedcase
    function DivisionByZeroError()
        internal
        pure
        returns (bytes memory)
    {
        return DIVISION_BY_ZERO_ERROR;
    }

    function RoundingError(
        uint256 numerator,
        uint256 denominator,
        uint256 target
    )
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            ROUNDING_ERROR_SELECTOR,
            numerator,
            denominator,
            target
        );
    }
}

File 28 of 58 : MixinCumulativeRewards.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;
pragma experimental ABIEncoderV2;

import "@0x/contracts-utils/contracts/src/LibFractions.sol";
import "@0x/contracts-utils/contracts/src/LibSafeMath.sol";
import "../stake/MixinStakeBalances.sol";
import "../immutable/MixinConstants.sol";


contract MixinCumulativeRewards is
    MixinStakeBalances,
    MixinConstants
{
    using LibSafeMath for uint256;

    /// @dev returns true iff Cumulative Rewards are set
    function _isCumulativeRewardSet(IStructs.Fraction memory cumulativeReward)
        internal
        pure
        returns (bool)
    {
        // We use the denominator as a proxy for whether the cumulative
        // reward is set, as setting the cumulative reward always sets this
        // field to at least 1.
        return cumulativeReward.denominator != 0;
    }

    /// @dev Sets a pool's cumulative delegator rewards for the current epoch,
    ///      given the rewards earned and stake from the last epoch, which will
    ///      be summed with the previous cumulative rewards for this pool.
    ///      If the last cumulative reward epoch is the current epoch, this is a
    ///      no-op.
    /// @param poolId The pool ID.
    /// @param reward The total reward earned by pool delegators from the last epoch.
    /// @param stake The total delegated stake in the pool in the last epoch.
    function _addCumulativeReward(
        bytes32 poolId,
        uint256 reward,
        uint256 stake
    )
        internal
    {
        // Fetch the last epoch at which we stored an entry for this pool;
        // this is the most up-to-date cumulative rewards for this pool.
        uint256 lastStoredEpoch = _cumulativeRewardsByPoolLastStored[poolId];
        uint256 currentEpoch_ = currentEpoch;

        // If we already have a record for this epoch, don't overwrite it.
        if (lastStoredEpoch == currentEpoch_) {
            return;
        }

        IStructs.Fraction memory mostRecentCumulativeReward =
            _cumulativeRewardsByPool[poolId][lastStoredEpoch];

        // Compute new cumulative reward
        IStructs.Fraction memory cumulativeReward;
        if (_isCumulativeRewardSet(mostRecentCumulativeReward)) {
            // If we have a prior cumulative reward entry, we sum them as fractions.
            (cumulativeReward.numerator, cumulativeReward.denominator) = LibFractions.add(
                mostRecentCumulativeReward.numerator,
                mostRecentCumulativeReward.denominator,
                reward,
                stake
            );
            // Normalize to prevent overflows in future operations.
            (cumulativeReward.numerator, cumulativeReward.denominator) = LibFractions.normalize(
                cumulativeReward.numerator,
                cumulativeReward.denominator
            );
        } else {
            (cumulativeReward.numerator, cumulativeReward.denominator) = (reward, stake);
        }

        // Store cumulative rewards for this epoch.
        _cumulativeRewardsByPool[poolId][currentEpoch_] = cumulativeReward;
        _cumulativeRewardsByPoolLastStored[poolId] = currentEpoch_;
    }

    /// @dev Sets a pool's cumulative delegator rewards for the current epoch,
    ///      using the last stored cumulative rewards. If we've already set
    ///      a CR for this epoch, this is a no-op.
    /// @param poolId The pool ID.
    function _updateCumulativeReward(bytes32 poolId)
        internal
    {
        // Just add empty rewards for this epoch, which will be added to
        // the previous CR, so we end up with the previous CR being set for
        // this epoch.
        _addCumulativeReward(poolId, 0, 1);
    }

    /// @dev Computes a member's reward over a given epoch interval.
    /// @param poolId Uniqud Id of pool.
    /// @param memberStakeOverInterval Stake delegated to pool by member over
    ///        the interval.
    /// @param beginEpoch Beginning of interval.
    /// @param endEpoch End of interval.
    /// @return rewards Reward accumulated over interval [beginEpoch, endEpoch]
    function _computeMemberRewardOverInterval(
        bytes32 poolId,
        uint256 memberStakeOverInterval,
        uint256 beginEpoch,
        uint256 endEpoch
    )
        internal
        view
        returns (uint256 reward)
    {
        // Sanity check if we can skip computation, as it will result in zero.
        if (memberStakeOverInterval == 0 || beginEpoch == endEpoch) {
            return 0;
        }

        // Sanity check interval
        require(beginEpoch < endEpoch, "CR_INTERVAL_INVALID");

        // Sanity check begin reward
        IStructs.Fraction memory beginReward = _getCumulativeRewardAtEpoch(poolId, beginEpoch);
        IStructs.Fraction memory endReward = _getCumulativeRewardAtEpoch(poolId, endEpoch);

        // Compute reward
        reward = LibFractions.scaleDifference(
            endReward.numerator,
            endReward.denominator,
            beginReward.numerator,
            beginReward.denominator,
            memberStakeOverInterval
        );
    }

    /// @dev Fetch the most recent cumulative reward entry for a pool.
    /// @param poolId Unique ID of pool.
    /// @return cumulativeReward The most recent cumulative reward `poolId`.
    function _getMostRecentCumulativeReward(bytes32 poolId)
        private
        view
        returns (IStructs.Fraction memory cumulativeReward)
    {
        uint256 lastStoredEpoch = _cumulativeRewardsByPoolLastStored[poolId];
        return _cumulativeRewardsByPool[poolId][lastStoredEpoch];
    }

    /// @dev Fetch the cumulative reward for a given epoch.
    ///      If the corresponding CR does not exist in state, then we backtrack
    ///      to find its value by querying `epoch-1` and then most recent CR.
    /// @param poolId Unique ID of pool.
    /// @param epoch The epoch to find the
    /// @return cumulativeReward The cumulative reward for `poolId` at `epoch`.
    /// @return cumulativeRewardStoredAt Epoch that the `cumulativeReward` is stored at.
    function _getCumulativeRewardAtEpoch(bytes32 poolId, uint256 epoch)
        private
        view
        returns (IStructs.Fraction memory cumulativeReward)
    {
        // Return CR at `epoch`, given it's set.
        cumulativeReward = _cumulativeRewardsByPool[poolId][epoch];
        if (_isCumulativeRewardSet(cumulativeReward)) {
            return cumulativeReward;
        }

        // Return CR at `epoch-1`, given it's set.
        uint256 lastEpoch = epoch.safeSub(1);
        cumulativeReward = _cumulativeRewardsByPool[poolId][lastEpoch];
        if (_isCumulativeRewardSet(cumulativeReward)) {
            return cumulativeReward;
        }

        // Return the most recent CR, given it's less than `epoch`.
        uint256 mostRecentEpoch = _cumulativeRewardsByPoolLastStored[poolId];
        if (mostRecentEpoch < epoch) {
            cumulativeReward = _cumulativeRewardsByPool[poolId][mostRecentEpoch];
            if (_isCumulativeRewardSet(cumulativeReward)) {
                return cumulativeReward;
            }
        }

        // Otherwise return an empty CR.
        return IStructs.Fraction(0, 1);
    }
}

File 29 of 58 : LibFractions.sol
pragma solidity ^0.5.9;

import "./LibSafeMath.sol";


library LibFractions {

    using LibSafeMath for uint256;

    /// @dev Safely adds two fractions `n1/d1 + n2/d2`
    /// @param n1 numerator of `1`
    /// @param d1 denominator of `1`
    /// @param n2 numerator of `2`
    /// @param d2 denominator of `2`
    /// @return numerator Numerator of sum
    /// @return denominator Denominator of sum
    function add(
        uint256 n1,
        uint256 d1,
        uint256 n2,
        uint256 d2
    )
        internal
        pure
        returns (
            uint256 numerator,
            uint256 denominator
        )
    {
        if (n1 == 0) {
            return (numerator = n2, denominator = d2);
        }
        if (n2 == 0) {
            return (numerator = n1, denominator = d1);
        }
        numerator = n1
            .safeMul(d2)
            .safeAdd(n2.safeMul(d1));
        denominator = d1.safeMul(d2);
        return (numerator, denominator);
    }

    /// @dev Rescales a fraction to prevent overflows during addition if either
    ///      the numerator or the denominator are > `maxValue`.
    /// @param numerator The numerator.
    /// @param denominator The denominator.
    /// @param maxValue The maximum value allowed for both the numerator and
    ///        denominator.
    /// @return scaledNumerator The rescaled numerator.
    /// @return scaledDenominator The rescaled denominator.
    function normalize(
        uint256 numerator,
        uint256 denominator,
        uint256 maxValue
    )
        internal
        pure
        returns (
            uint256 scaledNumerator,
            uint256 scaledDenominator
        )
    {
        // If either the numerator or the denominator are > `maxValue`,
        // re-scale them by `maxValue` to prevent overflows in future operations.
        if (numerator > maxValue || denominator > maxValue) {
            uint256 rescaleBase = numerator >= denominator ? numerator : denominator;
            rescaleBase = rescaleBase.safeDiv(maxValue);
            scaledNumerator = numerator.safeDiv(rescaleBase);
            scaledDenominator = denominator.safeDiv(rescaleBase);
        } else {
            scaledNumerator = numerator;
            scaledDenominator = denominator;
        }
        return (scaledNumerator, scaledDenominator);
    }

    /// @dev Rescales a fraction to prevent overflows during addition if either
    ///      the numerator or the denominator are > 2 ** 127.
    /// @param numerator The numerator.
    /// @param denominator The denominator.
    /// @return scaledNumerator The rescaled numerator.
    /// @return scaledDenominator The rescaled denominator.
    function normalize(
        uint256 numerator,
        uint256 denominator
    )
        internal
        pure
        returns (
            uint256 scaledNumerator,
            uint256 scaledDenominator
        )
    {
        return normalize(numerator, denominator, 2 ** 127);
    }

    /// @dev Safely scales the difference between two fractions.
    /// @param n1 numerator of `1`
    /// @param d1 denominator of `1`
    /// @param n2 numerator of `2`
    /// @param d2 denominator of `2`
    /// @param s scalar to multiply by difference.
    /// @return result `s * (n1/d1 - n2/d2)`.
    function scaleDifference(
        uint256 n1,
        uint256 d1,
        uint256 n2,
        uint256 d2,
        uint256 s
    )
        internal
        pure
        returns (uint256 result)
    {
        if (s == 0) {
            return 0;
        }
        if (n2 == 0) {
            return result = s
                .safeMul(n1)
                .safeDiv(d1);
        }
        uint256 numerator = n1
            .safeMul(d2)
            .safeSub(n2.safeMul(d1));
        uint256 tmp = numerator.safeDiv(d2);
        return s
            .safeMul(tmp)
            .safeDiv(d1);
    }
}

File 30 of 58 : MixinStakeBalances.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;
pragma experimental ABIEncoderV2;

import "@0x/contracts-utils/contracts/src/LibSafeMath.sol";
import "../interfaces/IStructs.sol";
import "../immutable/MixinDeploymentConstants.sol";
import "./MixinStakeStorage.sol";


contract MixinStakeBalances is
    MixinStakeStorage,
    MixinDeploymentConstants
{
    using LibSafeMath for uint256;

    /// @dev Gets global stake for a given status.
    /// @param stakeStatus UNDELEGATED or DELEGATED
    /// @return Global stake for given status.
    function getGlobalStakeByStatus(IStructs.StakeStatus stakeStatus)
        external
        view
        returns (IStructs.StoredBalance memory balance)
    {
        balance = _loadCurrentBalance(
            _globalStakeByStatus[uint8(IStructs.StakeStatus.DELEGATED)]
        );
        if (stakeStatus == IStructs.StakeStatus.UNDELEGATED) {
            // Undelegated stake is the difference between total stake and delegated stake
            // Note that any ZRX erroneously sent to the vault will be counted as undelegated stake
            uint256 totalStake = getZrxVault().balanceOfZrxVault();
            balance.currentEpochBalance = totalStake.safeSub(balance.currentEpochBalance).downcastToUint96();
            balance.nextEpochBalance = totalStake.safeSub(balance.nextEpochBalance).downcastToUint96();
        }
        return balance;
    }

    /// @dev Gets an owner's stake balances by status.
    /// @param staker Owner of stake.
    /// @param stakeStatus UNDELEGATED or DELEGATED
    /// @return Owner's stake balances for given status.
    function getOwnerStakeByStatus(
        address staker,
        IStructs.StakeStatus stakeStatus
    )
        external
        view
        returns (IStructs.StoredBalance memory balance)
    {
        balance = _loadCurrentBalance(
            _ownerStakeByStatus[uint8(stakeStatus)][staker]
        );
        return balance;
    }

    /// @dev Returns the total stake for a given staker.
    /// @param staker of stake.
    /// @return Total ZRX staked by `staker`.
    function getTotalStake(address staker)
        public
        view
        returns (uint256)
    {
        return getZrxVault().balanceOf(staker);
    }

    /// @dev Returns the stake delegated to a specific staking pool, by a given staker.
    /// @param staker of stake.
    /// @param poolId Unique Id of pool.
    /// @return Stake delegated to pool by staker.
    function getStakeDelegatedToPoolByOwner(address staker, bytes32 poolId)
        public
        view
        returns (IStructs.StoredBalance memory balance)
    {
        balance = _loadCurrentBalance(_delegatedStakeToPoolByOwner[staker][poolId]);
        return balance;
    }

    /// @dev Returns the total stake delegated to a specific staking pool,
    ///      across all members.
    /// @param poolId Unique Id of pool.
    /// @return Total stake delegated to pool.
    function getTotalStakeDelegatedToPool(bytes32 poolId)
        public
        view
        returns (IStructs.StoredBalance memory balance)
    {
        balance = _loadCurrentBalance(_delegatedStakeByPoolId[poolId]);
        return balance;
    }
}

File 31 of 58 : MixinDeploymentConstants.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;

import "@0x/contracts-erc20/contracts/src/interfaces/IEtherToken.sol";
import "../interfaces/IZrxVault.sol";


// solhint-disable separate-by-one-line-in-contract
contract MixinDeploymentConstants {

    // @TODO SET THESE VALUES FOR DEPLOYMENT

    // Mainnet WETH9 Address
    address constant private WETH_ADDRESS = address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);

    // Kovan WETH9 Address
    // address constant private WETH_ADDRESS = address(0xd0A1E359811322d97991E03f863a0C30C2cF029C);

    // Ropsten & Rinkeby WETH9 Address
    // address constant private WETH_ADDRESS = address(0xc778417E063141139Fce010982780140Aa0cD5Ab);

    // @TODO SET THESE VALUES FOR DEPLOYMENT

    // Mainnet ZrxVault address
    address constant private ZRX_VAULT_ADDRESS = address(0xBa7f8b5fB1b19c1211c5d49550fcD149177A5Eaf);

    // Kovan ZrxVault address
    // address constant private ZRX_VAULT_ADDRESS = address(0xf36eabdFE986B35b62c8FD5a98A7f2aEBB79B291);

    // Ropsten ZrxVault address
    // address constant private ZRX_VAULT_ADDRESS = address(0xffD161026865Ad8B4aB28a76840474935eEc4DfA);

    // Rinkeby ZrxVault address
    // address constant private ZRX_VAULT_ADDRESS = address(0xA5Bf6aC73bC40790FC6Ffc9DBbbCE76c9176e224);

    /// @dev An overridable way to access the deployed WETH contract.
    ///      Must be view to allow overrides to access state.
    /// @return wethContract The WETH contract instance.
    function getWethContract()
        public
        view
        returns (IEtherToken wethContract)
    {
        wethContract = IEtherToken(WETH_ADDRESS);
        return wethContract;
    }

    /// @dev An overridable way to access the deployed zrxVault.
    ///      Must be view to allow overrides to access state.
    /// @return zrxVault The zrxVault contract.
    function getZrxVault()
        public
        view
        returns (IZrxVault zrxVault)
    {
        zrxVault = IZrxVault(ZRX_VAULT_ADDRESS);
        return zrxVault;
    }
}

File 32 of 58 : MixinStakeStorage.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;

import "../libs/LibSafeDowncast.sol";
import "@0x/contracts-utils/contracts/src/LibSafeMath.sol";
import "../interfaces/IStructs.sol";
import "../sys/MixinScheduler.sol";


/// @dev This mixin contains logic for managing stake storage.
contract MixinStakeStorage is
    MixinScheduler
{
    using LibSafeMath for uint256;
    using LibSafeDowncast for uint256;

    /// @dev Moves stake between states: 'undelegated' or 'delegated'.
    ///      This change comes into effect next epoch.
    /// @param fromPtr pointer to storage location of `from` stake.
    /// @param toPtr pointer to storage location of `to` stake.
    /// @param amount of stake to move.
    function _moveStake(
        IStructs.StoredBalance storage fromPtr,
        IStructs.StoredBalance storage toPtr,
        uint256 amount
    )
        internal
    {
        // do nothing if pointers are equal
        if (_arePointersEqual(fromPtr, toPtr)) {
            return;
        }

        // load current balances from storage
        IStructs.StoredBalance memory from = _loadCurrentBalance(fromPtr);
        IStructs.StoredBalance memory to = _loadCurrentBalance(toPtr);

        // sanity check on balance
        if (amount > from.nextEpochBalance) {
            LibRichErrors.rrevert(
                LibStakingRichErrors.InsufficientBalanceError(
                    amount,
                    from.nextEpochBalance
                )
            );
        }

        // move stake for next epoch
        from.nextEpochBalance = uint256(from.nextEpochBalance).safeSub(amount).downcastToUint96();
        to.nextEpochBalance = uint256(to.nextEpochBalance).safeAdd(amount).downcastToUint96();

        // update state in storage
        _storeBalance(fromPtr, from);
        _storeBalance(toPtr, to);
    }

    /// @dev Loads a balance from storage and updates its fields to reflect values for the current epoch.
    /// @param balancePtr to load.
    /// @return current balance.
    function _loadCurrentBalance(IStructs.StoredBalance storage balancePtr)
        internal
        view
        returns (IStructs.StoredBalance memory balance)
    {
        balance = balancePtr;
        uint256 currentEpoch_ = currentEpoch;
        if (currentEpoch_ > balance.currentEpoch) {
            balance.currentEpoch = currentEpoch_.downcastToUint64();
            balance.currentEpochBalance = balance.nextEpochBalance;
        }
        return balance;
    }

    /// @dev Increments both the `current` and `next` fields.
    /// @param balancePtr storage pointer to balance.
    /// @param amount to mint.
    function _increaseCurrentAndNextBalance(IStructs.StoredBalance storage balancePtr, uint256 amount)
        internal
    {
        // Remove stake from balance
        IStructs.StoredBalance memory balance = _loadCurrentBalance(balancePtr);
        balance.nextEpochBalance = uint256(balance.nextEpochBalance).safeAdd(amount).downcastToUint96();
        balance.currentEpochBalance = uint256(balance.currentEpochBalance).safeAdd(amount).downcastToUint96();

        // update state
        _storeBalance(balancePtr, balance);
    }

    /// @dev Decrements both the `current` and `next` fields.
    /// @param balancePtr storage pointer to balance.
    /// @param amount to mint.
    function _decreaseCurrentAndNextBalance(IStructs.StoredBalance storage balancePtr, uint256 amount)
        internal
    {
        // Remove stake from balance
        IStructs.StoredBalance memory balance = _loadCurrentBalance(balancePtr);
        balance.nextEpochBalance = uint256(balance.nextEpochBalance).safeSub(amount).downcastToUint96();
        balance.currentEpochBalance = uint256(balance.currentEpochBalance).safeSub(amount).downcastToUint96();

        // update state
        _storeBalance(balancePtr, balance);
    }

    /// @dev Increments the `next` field (but not the `current` field).
    /// @param balancePtr storage pointer to balance.
    /// @param amount to increment by.
    function _increaseNextBalance(IStructs.StoredBalance storage balancePtr, uint256 amount)
        internal
    {
        // Add stake to balance
        IStructs.StoredBalance memory balance = _loadCurrentBalance(balancePtr);
        balance.nextEpochBalance = uint256(balance.nextEpochBalance).safeAdd(amount).downcastToUint96();

        // update state
        _storeBalance(balancePtr, balance);
    }

    /// @dev Decrements the `next` field (but not the `current` field).
    /// @param balancePtr storage pointer to balance.
    /// @param amount to decrement by.
    function _decreaseNextBalance(IStructs.StoredBalance storage balancePtr, uint256 amount)
        internal
    {
        // Remove stake from balance
        IStructs.StoredBalance memory balance = _loadCurrentBalance(balancePtr);
        balance.nextEpochBalance = uint256(balance.nextEpochBalance).safeSub(amount).downcastToUint96();

        // update state
        _storeBalance(balancePtr, balance);
    }

    /// @dev Stores a balance in storage.
    /// @param balancePtr points to where `balance` will be stored.
    /// @param balance to save to storage.
    function _storeBalance(
        IStructs.StoredBalance storage balancePtr,
        IStructs.StoredBalance memory balance
    )
        private
    {
        // note - this compresses into a single `sstore` when optimizations are enabled,
        // since the StoredBalance struct occupies a single word of storage.
        balancePtr.currentEpoch = balance.currentEpoch;
        balancePtr.nextEpochBalance = balance.nextEpochBalance;
        balancePtr.currentEpochBalance = balance.currentEpochBalance;
    }

    /// @dev Returns true iff storage pointers resolve to same storage location.
    /// @param balancePtrA first storage pointer.
    /// @param balancePtrB second storage pointer.
    /// @return true iff pointers are equal.
    function _arePointersEqual(
        // solhint-disable-next-line no-unused-vars
        IStructs.StoredBalance storage balancePtrA,
        // solhint-disable-next-line no-unused-vars
        IStructs.StoredBalance storage balancePtrB
    )
        private
        pure
        returns (bool areEqual)
    {
        assembly {
            areEqual := and(
                eq(balancePtrA_slot, balancePtrB_slot),
                eq(balancePtrA_offset, balancePtrB_offset)
            )
        }
        return areEqual;
    }
}

File 33 of 58 : LibSafeDowncast.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;

import "@0x/contracts-utils/contracts/src/LibRichErrors.sol";
import "@0x/contracts-utils/contracts/src/LibSafeMathRichErrors.sol";


library LibSafeDowncast {

    /// @dev Safely downcasts to a uint96
    /// Note that this reverts if the input value is too large.
    function downcastToUint96(uint256 a)
        internal
        pure
        returns (uint96 b)
    {
        b = uint96(a);
        if (uint256(b) != a) {
            LibRichErrors.rrevert(LibSafeMathRichErrors.Uint256DowncastError(
                LibSafeMathRichErrors.DowncastErrorCodes.VALUE_TOO_LARGE_TO_DOWNCAST_TO_UINT96,
                a
            ));
        }
        return b;
    }

    /// @dev Safely downcasts to a uint64
    /// Note that this reverts if the input value is too large.
    function downcastToUint64(uint256 a)
        internal
        pure
        returns (uint64 b)
    {
        b = uint64(a);
        if (uint256(b) != a) {
            LibRichErrors.rrevert(LibSafeMathRichErrors.Uint256DowncastError(
                LibSafeMathRichErrors.DowncastErrorCodes.VALUE_TOO_LARGE_TO_DOWNCAST_TO_UINT64,
                a
            ));
        }
        return b;
    }

    /// @dev Safely downcasts to a uint32
    /// Note that this reverts if the input value is too large.
    function downcastToUint32(uint256 a)
        internal
        pure
        returns (uint32 b)
    {
        b = uint32(a);
        if (uint256(b) != a) {
            LibRichErrors.rrevert(LibSafeMathRichErrors.Uint256DowncastError(
                LibSafeMathRichErrors.DowncastErrorCodes.VALUE_TOO_LARGE_TO_DOWNCAST_TO_UINT32,
                a
            ));
        }
        return b;
    }
}

File 34 of 58 : MixinScheduler.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;

import "@0x/contracts-utils/contracts/src/LibRichErrors.sol";
import "@0x/contracts-utils/contracts/src/LibSafeMath.sol";
import "../libs/LibStakingRichErrors.sol";
import "../immutable/MixinStorage.sol";
import "../interfaces/IStakingEvents.sol";


contract MixinScheduler is
    IStakingEvents,
    MixinStorage
{
    using LibSafeMath for uint256;

    /// @dev Returns the earliest end time in seconds of this epoch.
    ///      The next epoch can begin once this time is reached.
    ///      Epoch period = [startTimeInSeconds..endTimeInSeconds)
    /// @return Time in seconds.
    function getCurrentEpochEarliestEndTimeInSeconds()
        public
        view
        returns (uint256)
    {
        return currentEpochStartTimeInSeconds.safeAdd(epochDurationInSeconds);
    }

    /// @dev Initializes state owned by this mixin.
    ///      Fails if state was already initialized.
    function _initMixinScheduler()
        internal
    {
        // assert the current values before overwriting them.
        _assertSchedulerNotInitialized();

        // solhint-disable-next-line
        currentEpochStartTimeInSeconds = block.timestamp;
        currentEpoch = 1;
    }

    /// @dev Moves to the next epoch, given the current epoch period has ended.
    ///      Time intervals that are measured in epochs (like timeLocks) are also incremented, given
    ///      their periods have ended.
    function _goToNextEpoch()
        internal
    {
        // get current timestamp
        // solhint-disable-next-line not-rely-on-time
        uint256 currentBlockTimestamp = block.timestamp;

        // validate that we can increment the current epoch
        uint256 epochEndTime = getCurrentEpochEarliestEndTimeInSeconds();
        if (epochEndTime > currentBlockTimestamp) {
            LibRichErrors.rrevert(LibStakingRichErrors.BlockTimestampTooLowError(
                epochEndTime,
                currentBlockTimestamp
            ));
        }

        // incremment epoch
        uint256 nextEpoch = currentEpoch.safeAdd(1);
        currentEpoch = nextEpoch;
        currentEpochStartTimeInSeconds = currentBlockTimestamp;
    }

    /// @dev Assert scheduler state before initializing it.
    /// This must be updated for each migration.
    function _assertSchedulerNotInitialized()
        internal
        view
    {
        if (currentEpochStartTimeInSeconds != 0) {
            LibRichErrors.rrevert(
                LibStakingRichErrors.InitializationError(
                    LibStakingRichErrors.InitializationErrorCodes.MixinSchedulerAlreadyInitialized
                )
            );
        }
    }
}

File 35 of 58 : MixinExchangeFees.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;
pragma experimental ABIEncoderV2;

import "@0x/contracts-exchange-libs/contracts/src/LibMath.sol";
import "@0x/contracts-utils/contracts/src/LibRichErrors.sol";
import "@0x/contracts-utils/contracts/src/LibSafeMath.sol";
import "../libs/LibStakingRichErrors.sol";
import "../interfaces/IStructs.sol";
import "../sys/MixinFinalizer.sol";
import "../staking_pools/MixinStakingPool.sol";
import "./MixinExchangeManager.sol";


contract MixinExchangeFees is
    MixinExchangeManager,
    MixinStakingPool,
    MixinFinalizer
{
    using LibSafeMath for uint256;

    /// @dev Pays a protocol fee in ETH or WETH.
    ///      Only a known 0x exchange can call this method. See
    ///      (MixinExchangeManager).
    /// @param makerAddress The address of the order's maker.
    /// @param payerAddress The address of the protocol fee payer.
    /// @param protocolFee The protocol fee amount. This is either passed as ETH or transferred as WETH.
    function payProtocolFee(
        address makerAddress,
        address payerAddress,
        uint256 protocolFee
    )
        external
        payable
        onlyExchange
    {
        _assertValidProtocolFee(protocolFee);

        // Transfer the protocol fee to this address if it should be paid in
        // WETH.
        if (msg.value == 0) {
            require(
                getWethContract().transferFrom(
                    payerAddress,
                    address(this),
                    protocolFee
                ),
                "WETH_TRANSFER_FAILED"
            );
        }

        // Get the pool id of the maker address.
        bytes32 poolId = poolIdByMaker[makerAddress];

        // Only attribute the protocol fee payment to a pool if the maker is
        // registered to a pool.
        if (poolId == NIL_POOL_ID) {
            return;
        }

        uint256 poolStake = getTotalStakeDelegatedToPool(poolId).currentEpochBalance;
        // Ignore pools with dust stake.
        if (poolStake < minimumPoolStake) {
            return;
        }

        // Look up the pool stats and aggregated stats for this epoch.
        uint256 currentEpoch_ = currentEpoch;
        IStructs.PoolStats storage poolStatsPtr = poolStatsByEpoch[poolId][currentEpoch_];
        IStructs.AggregatedStats storage aggregatedStatsPtr = aggregatedStatsByEpoch[currentEpoch_];

        // Perform some initialization if this is the pool's first protocol fee in this epoch.
        uint256 feesCollectedByPool = poolStatsPtr.feesCollected;
        if (feesCollectedByPool == 0) {
            // Compute member and total weighted stake.
            (uint256 membersStakeInPool, uint256 weightedStakeInPool) = _computeMembersAndWeightedStake(poolId, poolStake);
            poolStatsPtr.membersStake = membersStakeInPool;
            poolStatsPtr.weightedStake = weightedStakeInPool;

            // Increase the total weighted stake.
            aggregatedStatsPtr.totalWeightedStake = aggregatedStatsPtr.totalWeightedStake.safeAdd(weightedStakeInPool);

            // Increase the number of pools to finalize.
            aggregatedStatsPtr.numPoolsToFinalize = aggregatedStatsPtr.numPoolsToFinalize.safeAdd(1);

            // Emit an event so keepers know what pools earned rewards this epoch.
            emit StakingPoolEarnedRewardsInEpoch(currentEpoch_, poolId);
        }

        // Credit the fees to the pool.
        poolStatsPtr.feesCollected = feesCollectedByPool.safeAdd(protocolFee);

        // Increase the total fees collected this epoch.
        aggregatedStatsPtr.totalFeesCollected = aggregatedStatsPtr.totalFeesCollected.safeAdd(protocolFee);
    }

    /// @dev Get stats on a staking pool in this epoch.
    /// @param poolId Pool Id to query.
    /// @return PoolStats struct for pool id.
    function getStakingPoolStatsThisEpoch(bytes32 poolId)
        external
        view
        returns (IStructs.PoolStats memory)
    {
        return poolStatsByEpoch[poolId][currentEpoch];
    }

    /// @dev Computes the members and weighted stake for a pool at the current
    ///      epoch.
    /// @param poolId ID of the pool.
    /// @param totalStake Total (unweighted) stake in the pool.
    /// @return membersStake Non-operator stake in the pool.
    /// @return weightedStake Weighted stake of the pool.
    function _computeMembersAndWeightedStake(
        bytes32 poolId,
        uint256 totalStake
    )
        private
        view
        returns (uint256 membersStake, uint256 weightedStake)
    {
        uint256 operatorStake = getStakeDelegatedToPoolByOwner(
            _poolById[poolId].operator,
            poolId
        ).currentEpochBalance;

        membersStake = totalStake.safeSub(operatorStake);
        weightedStake = operatorStake.safeAdd(
            LibMath.getPartialAmountFloor(
                rewardDelegatedStakeWeight,
                PPM_DENOMINATOR,
                membersStake
            )
        );
        return (membersStake, weightedStake);
    }

    /// @dev Checks that the protocol fee passed into `payProtocolFee()` is
    ///      valid.
    /// @param protocolFee The `protocolFee` parameter to
    ///        `payProtocolFee.`
    function _assertValidProtocolFee(uint256 protocolFee)
        private
        view
    {
        // The protocol fee must equal the value passed to the contract; unless
        // the value is zero, in which case the fee is taken in WETH.
        if (msg.value != protocolFee && msg.value != 0) {
            LibRichErrors.rrevert(
                LibStakingRichErrors.InvalidProtocolFeePaymentError(
                    protocolFee,
                    msg.value
                )
            );
        }
    }
}

File 36 of 58 : MixinFinalizer.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;
pragma experimental ABIEncoderV2;

import "@0x/contracts-utils/contracts/src/LibRichErrors.sol";
import "@0x/contracts-utils/contracts/src/LibSafeMath.sol";
import "../libs/LibCobbDouglas.sol";
import "../libs/LibStakingRichErrors.sol";
import "../interfaces/IStructs.sol";
import "../staking_pools/MixinStakingPoolRewards.sol";


contract MixinFinalizer is
    MixinStakingPoolRewards
{
    using LibSafeMath for uint256;

    /// @dev Begins a new epoch, preparing the prior one for finalization.
    ///      Throws if not enough time has passed between epochs or if the
    ///      previous epoch was not fully finalized.
    /// @return numPoolsToFinalize The number of unfinalized pools.
    function endEpoch()
        external
        returns (uint256)
    {
        uint256 currentEpoch_ = currentEpoch;
        uint256 prevEpoch = currentEpoch_.safeSub(1);

        // Make sure the previous epoch has been fully finalized.
        uint256 numPoolsToFinalizeFromPrevEpoch = aggregatedStatsByEpoch[prevEpoch].numPoolsToFinalize;
        if (numPoolsToFinalizeFromPrevEpoch != 0) {
            LibRichErrors.rrevert(
                LibStakingRichErrors.PreviousEpochNotFinalizedError(
                    prevEpoch,
                    numPoolsToFinalizeFromPrevEpoch
                )
            );
        }

        // Convert all ETH to WETH; the WETH balance of this contract is the total rewards.
        _wrapEth();

        // Load aggregated stats for the epoch we're ending.
        aggregatedStatsByEpoch[currentEpoch_].rewardsAvailable = _getAvailableWethBalance();
        IStructs.AggregatedStats memory aggregatedStats = aggregatedStatsByEpoch[currentEpoch_];

        // Emit an event.
        emit EpochEnded(
            currentEpoch_,
            aggregatedStats.numPoolsToFinalize,
            aggregatedStats.rewardsAvailable,
            aggregatedStats.totalFeesCollected,
            aggregatedStats.totalWeightedStake
        );

        // Advance the epoch. This will revert if not enough time has passed.
        _goToNextEpoch();

        // If there are no pools to finalize then the epoch is finalized.
        if (aggregatedStats.numPoolsToFinalize == 0) {
            emit EpochFinalized(currentEpoch_, 0, aggregatedStats.rewardsAvailable);
        }

        return aggregatedStats.numPoolsToFinalize;
    }

    /// @dev Instantly finalizes a single pool that earned rewards in the previous
    ///      epoch, crediting it rewards for members and withdrawing operator's
    ///      rewards as WETH. This can be called by internal functions that need
    ///      to finalize a pool immediately. Does nothing if the pool is already
    ///      finalized or did not earn rewards in the previous epoch.
    /// @param poolId The pool ID to finalize.
    function finalizePool(bytes32 poolId)
        external
    {
        // Compute relevant epochs
        uint256 currentEpoch_ = currentEpoch;
        uint256 prevEpoch = currentEpoch_.safeSub(1);

        // Load the aggregated stats into memory; noop if no pools to finalize.
        IStructs.AggregatedStats memory aggregatedStats = aggregatedStatsByEpoch[prevEpoch];
        if (aggregatedStats.numPoolsToFinalize == 0) {
            return;
        }

        // Noop if the pool did not earn rewards or already finalized (has no fees).
        IStructs.PoolStats memory poolStats = poolStatsByEpoch[poolId][prevEpoch];
        if (poolStats.feesCollected == 0) {
            return;
        }

        // Clear the pool stats so we don't finalize it again, and to recoup
        // some gas.
        delete poolStatsByEpoch[poolId][prevEpoch];

        // Compute the rewards.
        uint256 rewards = _getUnfinalizedPoolRewardsFromPoolStats(poolStats, aggregatedStats);

        // Pay the operator and update rewards for the pool.
        // Note that we credit at the CURRENT epoch even though these rewards
        // were earned in the previous epoch.
        (uint256 operatorReward, uint256 membersReward) = _syncPoolRewards(
            poolId,
            rewards,
            poolStats.membersStake
        );

        // Emit an event.
        emit RewardsPaid(
            currentEpoch_,
            poolId,
            operatorReward,
            membersReward
        );

        uint256 totalReward = operatorReward.safeAdd(membersReward);

        // Increase `totalRewardsFinalized`.
        aggregatedStatsByEpoch[prevEpoch].totalRewardsFinalized =
            aggregatedStats.totalRewardsFinalized =
            aggregatedStats.totalRewardsFinalized.safeAdd(totalReward);

        // Decrease the number of unfinalized pools left.
        aggregatedStatsByEpoch[prevEpoch].numPoolsToFinalize =
            aggregatedStats.numPoolsToFinalize =
            aggregatedStats.numPoolsToFinalize.safeSub(1);

        // If there are no more unfinalized pools remaining, the epoch is
        // finalized.
        if (aggregatedStats.numPoolsToFinalize == 0) {
            emit EpochFinalized(
                prevEpoch,
                aggregatedStats.totalRewardsFinalized,
                aggregatedStats.rewardsAvailable.safeSub(aggregatedStats.totalRewardsFinalized)
            );
        }
    }

    /// @dev Computes the reward owed to a pool during finalization.
    ///      Does nothing if the pool is already finalized.
    /// @param poolId The pool's ID.
    /// @return totalReward The total reward owed to a pool.
    /// @return membersStake The total stake for all non-operator members in
    ///         this pool.
    function _getUnfinalizedPoolRewards(bytes32 poolId)
        internal
        view
        returns (
            uint256 reward,
            uint256 membersStake
        )
    {
        uint256 prevEpoch = currentEpoch.safeSub(1);
        IStructs.PoolStats memory poolStats = poolStatsByEpoch[poolId][prevEpoch];
        reward = _getUnfinalizedPoolRewardsFromPoolStats(poolStats, aggregatedStatsByEpoch[prevEpoch]);
        membersStake = poolStats.membersStake;
    }

    /// @dev Converts the entire ETH balance of this contract into WETH.
    function _wrapEth()
        internal
    {
        uint256 ethBalance = address(this).balance;
        if (ethBalance != 0) {
            getWethContract().deposit.value(ethBalance)();
        }
    }

    /// @dev Returns the WETH balance of this contract, minus
    ///      any WETH that has already been reserved for rewards.
    function _getAvailableWethBalance()
        internal
        view
        returns (uint256 wethBalance)
    {
        wethBalance = getWethContract().balanceOf(address(this))
            .safeSub(wethReservedForPoolRewards);

        return wethBalance;
    }

    /// @dev Asserts that a pool has been finalized last epoch.
    /// @param poolId The id of the pool that should have been finalized.
    function _assertPoolFinalizedLastEpoch(bytes32 poolId)
        internal
        view
    {
        uint256 prevEpoch = currentEpoch.safeSub(1);
        IStructs.PoolStats memory poolStats = poolStatsByEpoch[poolId][prevEpoch];

        // A pool that has any fees remaining has not been finalized
        if (poolStats.feesCollected != 0) {
            LibRichErrors.rrevert(
                LibStakingRichErrors.PoolNotFinalizedError(
                    poolId,
                    prevEpoch
                )
            );
        }
    }

    /// @dev Computes the reward owed to a pool during finalization.
    /// @param poolStats Stats for a specific pool.
    /// @param aggregatedStats Stats aggregated across all pools.
    /// @return rewards Unfinalized rewards for the input pool.
    function _getUnfinalizedPoolRewardsFromPoolStats(
        IStructs.PoolStats memory poolStats,
        IStructs.AggregatedStats memory aggregatedStats
    )
        private
        view
        returns (uint256 rewards)
    {
        // There can't be any rewards if the pool did not collect any fees.
        if (poolStats.feesCollected == 0) {
            return rewards;
        }

        // Use the cobb-douglas function to compute the total reward.
        rewards = LibCobbDouglas.cobbDouglas(
            aggregatedStats.rewardsAvailable,
            poolStats.feesCollected,
            aggregatedStats.totalFeesCollected,
            poolStats.weightedStake,
            aggregatedStats.totalWeightedStake,
            cobbDouglasAlphaNumerator,
            cobbDouglasAlphaDenominator
        );

        // Clip the reward to always be under
        // `rewardsAvailable - totalRewardsPaid`,
        // in case cobb-douglas overflows, which should be unlikely.
        uint256 rewardsRemaining = aggregatedStats.rewardsAvailable.safeSub(aggregatedStats.totalRewardsFinalized);
        if (rewardsRemaining < rewards) {
            rewards = rewardsRemaining;
        }
    }
}

File 37 of 58 : LibCobbDouglas.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;
pragma experimental ABIEncoderV2;

import "./LibFixedMath.sol";


library LibCobbDouglas {

    /// @dev The cobb-douglas function used to compute fee-based rewards for
    ///      staking pools in a given epoch. This function does not perform
    ///      bounds checking on the inputs, but the following conditions
    ///      need to be true:
    ///         0 <= fees / totalFees <= 1
    ///         0 <= stake / totalStake <= 1
    ///         0 <= alphaNumerator / alphaDenominator <= 1
    /// @param totalRewards collected over an epoch.
    /// @param fees Fees attributed to the the staking pool.
    /// @param totalFees Total fees collected across all pools that earned rewards.
    /// @param stake Stake attributed to the staking pool.
    /// @param totalStake Total stake across all pools that earned rewards.
    /// @param alphaNumerator Numerator of `alpha` in the cobb-douglas function.
    /// @param alphaDenominator Denominator of `alpha` in the cobb-douglas
    ///        function.
    /// @return rewards Rewards owed to the staking pool.
    function cobbDouglas(
        uint256 totalRewards,
        uint256 fees,
        uint256 totalFees,
        uint256 stake,
        uint256 totalStake,
        uint32 alphaNumerator,
        uint32 alphaDenominator
    )
        internal
        pure
        returns (uint256 rewards)
    {
        int256 feeRatio = LibFixedMath.toFixed(fees, totalFees);
        int256 stakeRatio = LibFixedMath.toFixed(stake, totalStake);
        if (feeRatio == 0 || stakeRatio == 0) {
            return rewards = 0;
        }
        // The cobb-doublas function has the form:
        // `totalRewards * feeRatio ^ alpha * stakeRatio ^ (1-alpha)`
        // This is equivalent to:
        // `totalRewards * stakeRatio * e^(alpha * (ln(feeRatio / stakeRatio)))`
        // However, because `ln(x)` has the domain of `0 < x < 1`
        // and `exp(x)` has the domain of `x < 0`,
        // and fixed-point math easily overflows with multiplication,
        // we will choose the following if `stakeRatio > feeRatio`:
        // `totalRewards * stakeRatio / e^(alpha * (ln(stakeRatio / feeRatio)))`

        // Compute
        // `e^(alpha * ln(feeRatio/stakeRatio))` if feeRatio <= stakeRatio
        // or
        // `e^(alpa * ln(stakeRatio/feeRatio))` if feeRatio > stakeRatio
        int256 n = feeRatio <= stakeRatio ?
            LibFixedMath.div(feeRatio, stakeRatio) :
            LibFixedMath.div(stakeRatio, feeRatio);
        n = LibFixedMath.exp(
            LibFixedMath.mulDiv(
                LibFixedMath.ln(n),
                int256(alphaNumerator),
                int256(alphaDenominator)
            )
        );
        // Compute
        // `totalRewards * n` if feeRatio <= stakeRatio
        // or
        // `totalRewards / n` if stakeRatio > feeRatio
        // depending on the choice we made earlier.
        n = feeRatio <= stakeRatio ?
            LibFixedMath.mul(stakeRatio, n) :
            LibFixedMath.div(stakeRatio, n);
        // Multiply the above with totalRewards.
        rewards = LibFixedMath.uintMul(n, totalRewards);
    }
}

File 38 of 58 : LibFixedMath.sol
/*

  Copyright 2017 Bprotocol Foundation, 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;

import "./LibFixedMathRichErrors.sol";


// solhint-disable indent
/// @dev Signed, fixed-point, 127-bit precision math library.
library LibFixedMath {

    // 1
    int256 private constant FIXED_1 = int256(0x0000000000000000000000000000000080000000000000000000000000000000);
    // 2**255
    int256 private constant MIN_FIXED_VAL = int256(0x8000000000000000000000000000000000000000000000000000000000000000);
    // 1^2 (in fixed-point)
    int256 private constant FIXED_1_SQUARED = int256(0x4000000000000000000000000000000000000000000000000000000000000000);
    // 1
    int256 private constant LN_MAX_VAL = FIXED_1;
    // e ^ -63.875
    int256 private constant LN_MIN_VAL = int256(0x0000000000000000000000000000000000000000000000000000000733048c5a);
    // 0
    int256 private constant EXP_MAX_VAL = 0;
    // -63.875
    int256 private constant EXP_MIN_VAL = -int256(0x0000000000000000000000000000001ff0000000000000000000000000000000);

    /// @dev Get one as a fixed-point number.
    function one() internal pure returns (int256 f) {
        f = FIXED_1;
    }

    /// @dev Returns the addition of two fixed point numbers, reverting on overflow.
    function add(int256 a, int256 b) internal pure returns (int256 c) {
        c = _add(a, b);
    }

    /// @dev Returns the addition of two fixed point numbers, reverting on overflow.
    function sub(int256 a, int256 b) internal pure returns (int256 c) {
        if (b == MIN_FIXED_VAL) {
            LibRichErrors.rrevert(LibFixedMathRichErrors.SignedValueError(
                LibFixedMathRichErrors.ValueErrorCodes.TOO_SMALL,
                b
            ));
        }
        c = _add(a, -b);
    }

    /// @dev Returns the multiplication of two fixed point numbers, reverting on overflow.
    function mul(int256 a, int256 b) internal pure returns (int256 c) {
        c = _mul(a, b) / FIXED_1;
    }

    /// @dev Returns the division of two fixed point numbers.
    function div(int256 a, int256 b) internal pure returns (int256 c) {
        c = _div(_mul(a, FIXED_1), b);
    }

    /// @dev Performs (a * n) / d, without scaling for precision.
    function mulDiv(int256 a, int256 n, int256 d) internal pure returns (int256 c) {
        c = _div(_mul(a, n), d);
    }

    /// @dev Returns the unsigned integer result of multiplying a fixed-point
    ///      number with an integer, reverting if the multiplication overflows.
    ///      Negative results are clamped to zero.
    function uintMul(int256 f, uint256 u) internal pure returns (uint256) {
        if (int256(u) < int256(0)) {
            LibRichErrors.rrevert(LibFixedMathRichErrors.UnsignedValueError(
                LibFixedMathRichErrors.ValueErrorCodes.TOO_LARGE,
                u
            ));
        }
        int256 c = _mul(f, int256(u));
        if (c <= 0) {
            return 0;
        }
        return uint256(uint256(c) >> 127);
    }

    /// @dev Returns the absolute value of a fixed point number.
    function abs(int256 f) internal pure returns (int256 c) {
        if (f == MIN_FIXED_VAL) {
            LibRichErrors.rrevert(LibFixedMathRichErrors.SignedValueError(
                LibFixedMathRichErrors.ValueErrorCodes.TOO_SMALL,
                f
            ));
        }
        if (f >= 0) {
            c = f;
        } else {
            c = -f;
        }
    }

    /// @dev Returns 1 / `x`, where `x` is a fixed-point number.
    function invert(int256 f) internal pure returns (int256 c) {
        c = _div(FIXED_1_SQUARED, f);
    }

    /// @dev Convert signed `n` / 1 to a fixed-point number.
    function toFixed(int256 n) internal pure returns (int256 f) {
        f = _mul(n, FIXED_1);
    }

    /// @dev Convert signed `n` / `d` to a fixed-point number.
    function toFixed(int256 n, int256 d) internal pure returns (int256 f) {
        f = _div(_mul(n, FIXED_1), d);
    }

    /// @dev Convert unsigned `n` / 1 to a fixed-point number.
    ///      Reverts if `n` is too large to fit in a fixed-point number.
    function toFixed(uint256 n) internal pure returns (int256 f) {
        if (int256(n) < int256(0)) {
            LibRichErrors.rrevert(LibFixedMathRichErrors.UnsignedValueError(
                LibFixedMathRichErrors.ValueErrorCodes.TOO_LARGE,
                n
            ));
        }
        f = _mul(int256(n), FIXED_1);
    }

    /// @dev Convert unsigned `n` / `d` to a fixed-point number.
    ///      Reverts if `n` / `d` is too large to fit in a fixed-point number.
    function toFixed(uint256 n, uint256 d) internal pure returns (int256 f) {
        if (int256(n) < int256(0)) {
            LibRichErrors.rrevert(LibFixedMathRichErrors.UnsignedValueError(
                LibFixedMathRichErrors.ValueErrorCodes.TOO_LARGE,
                n
            ));
        }
        if (int256(d) < int256(0)) {
            LibRichErrors.rrevert(LibFixedMathRichErrors.UnsignedValueError(
                LibFixedMathRichErrors.ValueErrorCodes.TOO_LARGE,
                d
            ));
        }
        f = _div(_mul(int256(n), FIXED_1), int256(d));
    }

    /// @dev Convert a fixed-point number to an integer.
    function toInteger(int256 f) internal pure returns (int256 n) {
        return f / FIXED_1;
    }

    /// @dev Get the natural logarithm of a fixed-point number 0 < `x` <= LN_MAX_VAL
    function ln(int256 x) internal pure returns (int256 r) {
        if (x > LN_MAX_VAL) {
            LibRichErrors.rrevert(LibFixedMathRichErrors.SignedValueError(
                LibFixedMathRichErrors.ValueErrorCodes.TOO_LARGE,
                x
            ));
        }
        if (x <= 0) {
            LibRichErrors.rrevert(LibFixedMathRichErrors.SignedValueError(
                LibFixedMathRichErrors.ValueErrorCodes.TOO_SMALL,
                x
            ));
        }
        if (x == FIXED_1) {
            return 0;
        }
        if (x <= LN_MIN_VAL) {
            return EXP_MIN_VAL;
        }

        int256 y;
        int256 z;
        int256 w;

        // Rewrite the input as a quotient of negative natural exponents and a single residual q, such that 1 < q < 2
        // For example: log(0.3) = log(e^-1 * e^-0.25 * 1.0471028872385522)
        //              = 1 - 0.25 - log(1 + 0.0471028872385522)
        // e ^ -32
        if (x <= int256(0x00000000000000000000000000000000000000000001c8464f76164760000000)) {
            r -= int256(0x0000000000000000000000000000001000000000000000000000000000000000); // - 32
            x = x * FIXED_1 / int256(0x00000000000000000000000000000000000000000001c8464f76164760000000); // / e ^ -32
        }
        // e ^ -16
        if (x <= int256(0x00000000000000000000000000000000000000f1aaddd7742e90000000000000)) {
            r -= int256(0x0000000000000000000000000000000800000000000000000000000000000000); // - 16
            x = x * FIXED_1 / int256(0x00000000000000000000000000000000000000f1aaddd7742e90000000000000); // / e ^ -16
        }
        // e ^ -8
        if (x <= int256(0x00000000000000000000000000000000000afe10820813d78000000000000000)) {
            r -= int256(0x0000000000000000000000000000000400000000000000000000000000000000); // - 8
            x = x * FIXED_1 / int256(0x00000000000000000000000000000000000afe10820813d78000000000000000); // / e ^ -8
        }
        // e ^ -4
        if (x <= int256(0x0000000000000000000000000000000002582ab704279ec00000000000000000)) {
            r -= int256(0x0000000000000000000000000000000200000000000000000000000000000000); // - 4
            x = x * FIXED_1 / int256(0x0000000000000000000000000000000002582ab704279ec00000000000000000); // / e ^ -4
        }
        // e ^ -2
        if (x <= int256(0x000000000000000000000000000000001152aaa3bf81cc000000000000000000)) {
            r -= int256(0x0000000000000000000000000000000100000000000000000000000000000000); // - 2
            x = x * FIXED_1 / int256(0x000000000000000000000000000000001152aaa3bf81cc000000000000000000); // / e ^ -2
        }
        // e ^ -1
        if (x <= int256(0x000000000000000000000000000000002f16ac6c59de70000000000000000000)) {
            r -= int256(0x0000000000000000000000000000000080000000000000000000000000000000); // - 1
            x = x * FIXED_1 / int256(0x000000000000000000000000000000002f16ac6c59de70000000000000000000); // / e ^ -1
        }
        // e ^ -0.5
        if (x <= int256(0x000000000000000000000000000000004da2cbf1be5828000000000000000000)) {
            r -= int256(0x0000000000000000000000000000000040000000000000000000000000000000); // - 0.5
            x = x * FIXED_1 / int256(0x000000000000000000000000000000004da2cbf1be5828000000000000000000); // / e ^ -0.5
        }
        // e ^ -0.25
        if (x <= int256(0x0000000000000000000000000000000063afbe7ab2082c000000000000000000)) {
            r -= int256(0x0000000000000000000000000000000020000000000000000000000000000000); // - 0.25
            x = x * FIXED_1 / int256(0x0000000000000000000000000000000063afbe7ab2082c000000000000000000); // / e ^ -0.25
        }
        // e ^ -0.125
        if (x <= int256(0x0000000000000000000000000000000070f5a893b608861e1f58934f97aea57d)) {
            r -= int256(0x0000000000000000000000000000000010000000000000000000000000000000); // - 0.125
            x = x * FIXED_1 / int256(0x0000000000000000000000000000000070f5a893b608861e1f58934f97aea57d); // / e ^ -0.125
        }
        // `x` is now our residual in the range of 1 <= x <= 2 (or close enough).

        // Add the taylor series for log(1 + z), where z = x - 1
        z = y = x - FIXED_1;
        w = y * y / FIXED_1;
        r += z * (0x100000000000000000000000000000000 - y) / 0x100000000000000000000000000000000; z = z * w / FIXED_1; // add y^01 / 01 - y^02 / 02
        r += z * (0x0aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - y) / 0x200000000000000000000000000000000; z = z * w / FIXED_1; // add y^03 / 03 - y^04 / 04
        r += z * (0x099999999999999999999999999999999 - y) / 0x300000000000000000000000000000000; z = z * w / FIXED_1; // add y^05 / 05 - y^06 / 06
        r += z * (0x092492492492492492492492492492492 - y) / 0x400000000000000000000000000000000; z = z * w / FIXED_1; // add y^07 / 07 - y^08 / 08
        r += z * (0x08e38e38e38e38e38e38e38e38e38e38e - y) / 0x500000000000000000000000000000000; z = z * w / FIXED_1; // add y^09 / 09 - y^10 / 10
        r += z * (0x08ba2e8ba2e8ba2e8ba2e8ba2e8ba2e8b - y) / 0x600000000000000000000000000000000; z = z * w / FIXED_1; // add y^11 / 11 - y^12 / 12
        r += z * (0x089d89d89d89d89d89d89d89d89d89d89 - y) / 0x700000000000000000000000000000000; z = z * w / FIXED_1; // add y^13 / 13 - y^14 / 14
        r += z * (0x088888888888888888888888888888888 - y) / 0x800000000000000000000000000000000;                      // add y^15 / 15 - y^16 / 16
    }

    /// @dev Compute the natural exponent for a fixed-point number EXP_MIN_VAL <= `x` <= 1
    function exp(int256 x) internal pure returns (int256 r) {
        if (x < EXP_MIN_VAL) {
            // Saturate to zero below EXP_MIN_VAL.
            return 0;
        }
        if (x == 0) {
            return FIXED_1;
        }
        if (x > EXP_MAX_VAL) {
            LibRichErrors.rrevert(LibFixedMathRichErrors.SignedValueError(
                LibFixedMathRichErrors.ValueErrorCodes.TOO_LARGE,
                x
            ));
        }

        // Rewrite the input as a product of natural exponents and a
        // single residual q, where q is a number of small magnitude.
        // For example: e^-34.419 = e^(-32 - 2 - 0.25 - 0.125 - 0.044)
        //              = e^-32 * e^-2 * e^-0.25 * e^-0.125 * e^-0.044
        //              -> q = -0.044

        // Multiply with the taylor series for e^q
        int256 y;
        int256 z;
        // q = x % 0.125 (the residual)
        z = y = x % 0x0000000000000000000000000000000010000000000000000000000000000000;
        z = z * y / FIXED_1; r += z * 0x10e1b3be415a0000; // add y^02 * (20! / 02!)
        z = z * y / FIXED_1; r += z * 0x05a0913f6b1e0000; // add y^03 * (20! / 03!)
        z = z * y / FIXED_1; r += z * 0x0168244fdac78000; // add y^04 * (20! / 04!)
        z = z * y / FIXED_1; r += z * 0x004807432bc18000; // add y^05 * (20! / 05!)
        z = z * y / FIXED_1; r += z * 0x000c0135dca04000; // add y^06 * (20! / 06!)
        z = z * y / FIXED_1; r += z * 0x0001b707b1cdc000; // add y^07 * (20! / 07!)
        z = z * y / FIXED_1; r += z * 0x000036e0f639b800; // add y^08 * (20! / 08!)
        z = z * y / FIXED_1; r += z * 0x00000618fee9f800; // add y^09 * (20! / 09!)
        z = z * y / FIXED_1; r += z * 0x0000009c197dcc00; // add y^10 * (20! / 10!)
        z = z * y / FIXED_1; r += z * 0x0000000e30dce400; // add y^11 * (20! / 11!)
        z = z * y / FIXED_1; r += z * 0x000000012ebd1300; // add y^12 * (20! / 12!)
        z = z * y / FIXED_1; r += z * 0x0000000017499f00; // add y^13 * (20! / 13!)
        z = z * y / FIXED_1; r += z * 0x0000000001a9d480; // add y^14 * (20! / 14!)
        z = z * y / FIXED_1; r += z * 0x00000000001c6380; // add y^15 * (20! / 15!)
        z = z * y / FIXED_1; r += z * 0x000000000001c638; // add y^16 * (20! / 16!)
        z = z * y / FIXED_1; r += z * 0x0000000000001ab8; // add y^17 * (20! / 17!)
        z = z * y / FIXED_1; r += z * 0x000000000000017c; // add y^18 * (20! / 18!)
        z = z * y / FIXED_1; r += z * 0x0000000000000014; // add y^19 * (20! / 19!)
        z = z * y / FIXED_1; r += z * 0x0000000000000001; // add y^20 * (20! / 20!)
        r = r / 0x21c3677c82b40000 + y + FIXED_1; // divide by 20! and then add y^1 / 1! + y^0 / 0!

        // Multiply with the non-residual terms.
        x = -x;
        // e ^ -32
        if ((x & int256(0x0000000000000000000000000000001000000000000000000000000000000000)) != 0) {
            r = r * int256(0x00000000000000000000000000000000000000f1aaddd7742e56d32fb9f99744)
                / int256(0x0000000000000000000000000043cbaf42a000812488fc5c220ad7b97bf6e99e); // * e ^ -32
        }
        // e ^ -16
        if ((x & int256(0x0000000000000000000000000000000800000000000000000000000000000000)) != 0) {
            r = r * int256(0x00000000000000000000000000000000000afe10820813d65dfe6a33c07f738f)
                / int256(0x000000000000000000000000000005d27a9f51c31b7c2f8038212a0574779991); // * e ^ -16
        }
        // e ^ -8
        if ((x & int256(0x0000000000000000000000000000000400000000000000000000000000000000)) != 0) {
            r = r * int256(0x0000000000000000000000000000000002582ab704279e8efd15e0265855c47a)
                / int256(0x0000000000000000000000000000001b4c902e273a58678d6d3bfdb93db96d02); // * e ^ -8
        }
        // e ^ -4
        if ((x & int256(0x0000000000000000000000000000000200000000000000000000000000000000)) != 0) {
            r = r * int256(0x000000000000000000000000000000001152aaa3bf81cb9fdb76eae12d029571)
                / int256(0x00000000000000000000000000000003b1cc971a9bb5b9867477440d6d157750); // * e ^ -4
        }
        // e ^ -2
        if ((x & int256(0x0000000000000000000000000000000100000000000000000000000000000000)) != 0) {
            r = r * int256(0x000000000000000000000000000000002f16ac6c59de6f8d5d6f63c1482a7c86)
                / int256(0x000000000000000000000000000000015bf0a8b1457695355fb8ac404e7a79e3); // * e ^ -2
        }
        // e ^ -1
        if ((x & int256(0x0000000000000000000000000000000080000000000000000000000000000000)) != 0) {
            r = r * int256(0x000000000000000000000000000000004da2cbf1be5827f9eb3ad1aa9866ebb3)
                / int256(0x00000000000000000000000000000000d3094c70f034de4b96ff7d5b6f99fcd8); // * e ^ -1
        }
        // e ^ -0.5
        if ((x & int256(0x0000000000000000000000000000000040000000000000000000000000000000)) != 0) {
            r = r * int256(0x0000000000000000000000000000000063afbe7ab2082ba1a0ae5e4eb1b479dc)
                / int256(0x00000000000000000000000000000000a45af1e1f40c333b3de1db4dd55f29a7); // * e ^ -0.5
        }
        // e ^ -0.25
        if ((x & int256(0x0000000000000000000000000000000020000000000000000000000000000000)) != 0) {
            r = r * int256(0x0000000000000000000000000000000070f5a893b608861e1f58934f97aea57d)
                / int256(0x00000000000000000000000000000000910b022db7ae67ce76b441c27035c6a1); // * e ^ -0.25
        }
        // e ^ -0.125
        if ((x & int256(0x0000000000000000000000000000000010000000000000000000000000000000)) != 0) {
            r = r * int256(0x00000000000000000000000000000000783eafef1c0a8f3978c7f81824d62ebf)
                / int256(0x0000000000000000000000000000000088415abbe9a76bead8d00cf112e4d4a8); // * e ^ -0.125
        }
    }

    /// @dev Returns the multiplication two numbers, reverting on overflow.
    function _mul(int256 a, int256 b) private pure returns (int256 c) {
        if (a == 0) {
            return 0;
        }
        c = a * b;
        if (c / a != b || c / b != a) {
            LibRichErrors.rrevert(LibFixedMathRichErrors.BinOpError(
                LibFixedMathRichErrors.BinOpErrorCodes.MULTIPLICATION_OVERFLOW,
                a,
                b
            ));
        }
    }

    /// @dev Returns the division of two numbers, reverting on division by zero.
    function _div(int256 a, int256 b) private pure returns (int256 c) {
        if (b == 0) {
            LibRichErrors.rrevert(LibFixedMathRichErrors.BinOpError(
                LibFixedMathRichErrors.BinOpErrorCodes.DIVISION_BY_ZERO,
                a,
                b
            ));
        }
        if (a == MIN_FIXED_VAL && b == -1) {
            LibRichErrors.rrevert(LibFixedMathRichErrors.BinOpError(
                LibFixedMathRichErrors.BinOpErrorCodes.DIVISION_OVERFLOW,
                a,
                b
            ));
        }
        c = a / b;
    }

    /// @dev Adds two numbers, reverting on overflow.
    function _add(int256 a, int256 b) private pure returns (int256 c) {
        c = a + b;
        if ((a < 0 && b < 0 && c > a) || (a > 0 && b > 0 && c < a)) {
            LibRichErrors.rrevert(LibFixedMathRichErrors.BinOpError(
                LibFixedMathRichErrors.BinOpErrorCodes.ADDITION_OVERFLOW,
                a,
                b
            ));
        }
    }
}

File 39 of 58 : LibFixedMathRichErrors.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;

import "@0x/contracts-utils/contracts/src/LibRichErrors.sol";


library LibFixedMathRichErrors {

    enum ValueErrorCodes {
        TOO_SMALL,
        TOO_LARGE
    }

    enum BinOpErrorCodes {
        ADDITION_OVERFLOW,
        MULTIPLICATION_OVERFLOW,
        DIVISION_BY_ZERO,
        DIVISION_OVERFLOW
    }

    // bytes4(keccak256("SignedValueError(uint8,int256)"))
    bytes4 internal constant SIGNED_VALUE_ERROR_SELECTOR =
        0xed2f26a1;

    // bytes4(keccak256("UnsignedValueError(uint8,uint256)"))
    bytes4 internal constant UNSIGNED_VALUE_ERROR_SELECTOR =
        0xbd79545f;

    // bytes4(keccak256("BinOpError(uint8,int256,int256)"))
    bytes4 internal constant BIN_OP_ERROR_SELECTOR =
        0x8c12dfe7;

    // solhint-disable func-name-mixedcase
    function SignedValueError(
        ValueErrorCodes error,
        int256 n
    )
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            SIGNED_VALUE_ERROR_SELECTOR,
            uint8(error),
            n
        );
    }

    function UnsignedValueError(
        ValueErrorCodes error,
        uint256 n
    )
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            UNSIGNED_VALUE_ERROR_SELECTOR,
            uint8(error),
            n
        );
    }

    function BinOpError(
        BinOpErrorCodes error,
        int256 a,
        int256 b
    )
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            BIN_OP_ERROR_SELECTOR,
            uint8(error),
            a,
            b
        );
    }
}

File 40 of 58 : MixinExchangeManager.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;

import "@0x/contracts-utils/contracts/src/LibRichErrors.sol";
import "../libs/LibStakingRichErrors.sol";
import "../interfaces/IStakingEvents.sol";
import "../immutable/MixinStorage.sol";


contract MixinExchangeManager is
    IStakingEvents,
    MixinStorage
{
    /// @dev Asserts that the call is coming from a valid exchange.
    modifier onlyExchange() {
        if (!validExchanges[msg.sender]) {
            LibRichErrors.rrevert(LibStakingRichErrors.OnlyCallableByExchangeError(
                msg.sender
            ));
        }
        _;
    }

    /// @dev Adds a new exchange address
    /// @param addr Address of exchange contract to add
    function addExchangeAddress(address addr)
        external
        onlyAuthorized
    {
        if (validExchanges[addr]) {
            LibRichErrors.rrevert(LibStakingRichErrors.ExchangeManagerError(
                LibStakingRichErrors.ExchangeManagerErrorCodes.ExchangeAlreadyRegistered,
                addr
            ));
        }
        validExchanges[addr] = true;
        emit ExchangeAdded(addr);
    }

    /// @dev Removes an existing exchange address
    /// @param addr Address of exchange contract to remove
    function removeExchangeAddress(address addr)
        external
        onlyAuthorized
    {
        if (!validExchanges[addr]) {
            LibRichErrors.rrevert(LibStakingRichErrors.ExchangeManagerError(
                LibStakingRichErrors.ExchangeManagerErrorCodes.ExchangeNotRegistered,
                addr
            ));
        }
        validExchanges[addr] = false;
        emit ExchangeRemoved(addr);
    }
}

File 41 of 58 : TestCumulativeRewardTracking.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/
pragma solidity ^0.5.9;
pragma experimental ABIEncoderV2;

import "./TestStaking.sol";


// solhint-disable no-empty-blocks
contract TestCumulativeRewardTracking is
    TestStaking
{
    event SetCumulativeReward(
        bytes32 poolId,
        uint256 epoch
    );

    constructor(
        address wethAddress,
        address zrxVaultAddress
    )
        public
        TestStaking(
            wethAddress,
            zrxVaultAddress
        )
    {}

    function init() public {}

    function _addCumulativeReward(
        bytes32 poolId,
        uint256 reward,
        uint256 stake
    )
        internal
    {
        uint256 lastStoredEpoch = _cumulativeRewardsByPoolLastStored[poolId];
        MixinCumulativeRewards._addCumulativeReward(
            poolId,
            reward,
            stake
        );
        uint256 newLastStoredEpoch = _cumulativeRewardsByPoolLastStored[poolId];
        if (newLastStoredEpoch != lastStoredEpoch) {
            emit SetCumulativeReward(poolId, currentEpoch);
        }
    }
}

File 42 of 58 : TestStaking.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;
pragma experimental ABIEncoderV2;

import "@0x/contracts-asset-proxy/contracts/src/interfaces/IAssetData.sol";
import "@0x/contracts-erc20/contracts/src/interfaces/IEtherToken.sol";
import "../src/Staking.sol";


contract TestStaking is
    Staking
{
    address public testWethAddress;
    address public testZrxVaultAddress;

    constructor(
        address wethAddress,
        address zrxVaultAddress
    )
        public
    {
        testWethAddress = wethAddress;
        testZrxVaultAddress = zrxVaultAddress;
    }

    /// @dev Sets the weth contract address.
    /// @param wethAddress The address of the weth contract.
    function setWethContract(address wethAddress)
        external
    {
        testWethAddress = wethAddress;
    }

    /// @dev Sets the zrx vault address.
    /// @param zrxVaultAddress The address of a zrx vault.
    function setZrxVault(address zrxVaultAddress)
        external
    {
        testZrxVaultAddress = zrxVaultAddress;
    }

    /// @dev Overridden to use testWethAddress;
    function getWethContract()
        public
        view
        returns (IEtherToken)
    {
        // `testWethAddress` will not be set on the proxy this contract is
        // attached to, so we need to access the storage of the deployed
        // instance of this contract.
        address wethAddress = TestStaking(address(uint160(stakingContract))).testWethAddress();
        return IEtherToken(wethAddress);
    }

    function getZrxVault()
        public
        view
        returns (IZrxVault zrxVault)
    {
        address zrxVaultAddress = TestStaking(address(uint160(stakingContract))).testZrxVaultAddress();
        zrxVault = IZrxVault(zrxVaultAddress);
        return zrxVault;
    }
}

File 43 of 58 : IAssetData.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

// solhint-disable
pragma solidity ^0.5.9;
pragma experimental ABIEncoderV2;


// @dev Interface of the asset proxy's assetData.
// The asset proxies take an ABI encoded `bytes assetData` as argument.
// This argument is ABI encoded as one of the methods of this interface.
interface IAssetData {

    /// @dev Function signature for encoding ERC20 assetData.
    /// @param tokenAddress Address of ERC20Token contract.
    function ERC20Token(address tokenAddress)
        external;

    /// @dev Function signature for encoding ERC721 assetData.
    /// @param tokenAddress Address of ERC721 token contract.
    /// @param tokenId Id of ERC721 token to be transferred.
    function ERC721Token(
        address tokenAddress,
        uint256 tokenId
    )
        external;

    /// @dev Function signature for encoding ERC1155 assetData.
    /// @param tokenAddress Address of ERC1155 token contract.
    /// @param tokenIds Array of ids of tokens to be transferred.
    /// @param values Array of values that correspond to each token id to be transferred.
    ///        Note that each value will be multiplied by the amount being filled in the order before transferring.
    /// @param callbackData Extra data to be passed to receiver's `onERC1155Received` callback function.
    function ERC1155Assets(
        address tokenAddress,
        uint256[] calldata tokenIds,
        uint256[] calldata values,
        bytes calldata callbackData
    )
        external;

    /// @dev Function signature for encoding MultiAsset assetData.
    /// @param values Array of amounts that correspond to each asset to be transferred.
    ///        Note that each value will be multiplied by the amount being filled in the order before transferring.
    /// @param nestedAssetData Array of assetData fields that will be be dispatched to their correspnding AssetProxy contract.
    function MultiAsset(
        uint256[] calldata values,
        bytes[] calldata nestedAssetData
    )
        external;

    /// @dev Function signature for encoding StaticCall assetData.
    /// @param staticCallTargetAddress Address that will execute the staticcall.
    /// @param staticCallData Data that will be executed via staticcall on the staticCallTargetAddress.
    /// @param expectedReturnDataHash Keccak-256 hash of the expected staticcall return data.
    function StaticCall(
        address staticCallTargetAddress,
        bytes calldata staticCallData,
        bytes32 expectedReturnDataHash
    )
        external;

    /// @dev Function signature for encoding ERC20Bridge assetData.
    /// @param tokenAddress Address of token to transfer.
    /// @param bridgeAddress Address of the bridge contract.
    /// @param bridgeData Arbitrary data to be passed to the bridge contract.
    function ERC20Bridge(
        address tokenAddress,
        address bridgeAddress,
        bytes calldata bridgeData
    )
        external;
}

File 44 of 58 : TestDelegatorRewards.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;
pragma experimental ABIEncoderV2;

import "../src/interfaces/IStructs.sol";
import "./TestStakingNoWETH.sol";


contract TestDelegatorRewards is
    TestStakingNoWETH
{
    event FinalizePool(
        bytes32 poolId,
        uint256 operatorReward,
        uint256 membersReward,
        uint256 membersStake
    );

    struct UnfinalizedPoolReward {
        uint256 operatorReward;
        uint256 membersReward;
        uint256 membersStake;
    }

    constructor() public {
        _addAuthorizedAddress(msg.sender);
        init();
        _removeAuthorizedAddressAtIndex(msg.sender, 0);
    }

    mapping (uint256 => mapping (bytes32 => UnfinalizedPoolReward)) private
        unfinalizedPoolRewardsByEpoch;

    /// @dev Set unfinalized rewards for a pool in the current epoch.
    function setUnfinalizedPoolReward(
        bytes32 poolId,
        address payable operatorAddress,
        uint256 operatorReward,
        uint256 membersReward,
        uint256 membersStake
    )
        external
    {
        unfinalizedPoolRewardsByEpoch[currentEpoch][poolId] = UnfinalizedPoolReward({
            operatorReward: operatorReward,
            membersReward: membersReward,
            membersStake: membersStake
        });
        // Lazily initialize this pool.
        _poolById[poolId].operator = operatorAddress;
        _setOperatorShare(poolId, operatorReward, membersReward);
    }

    /// @dev Expose/wrap `_syncPoolRewards`.
    function syncPoolRewards(
        bytes32 poolId,
        address payable operatorAddress,
        uint256 operatorReward,
        uint256 membersReward,
        uint256 membersStake
    )
        external
    {
        // Lazily initialize this pool.
        _poolById[poolId].operator = operatorAddress;
        _setOperatorShare(poolId, operatorReward, membersReward);

        _syncPoolRewards(
            poolId,
            operatorReward + membersReward,
            membersStake
        );
    }

    /// @dev Advance the epoch.
    function advanceEpoch() external {
        currentEpoch += 1;
    }

    /// @dev Create and delegate stake to the current epoch.
    ///      Only used to test purportedly unreachable states.
    ///      Also withdraws pending rewards.
    function delegateStakeNow(
        address delegator,
        bytes32 poolId,
        uint256 stake
    )
        external
    {
        _withdrawAndSyncDelegatorRewards(
            poolId,
            delegator
        );
        IStructs.StoredBalance storage _stake = _delegatedStakeToPoolByOwner[delegator][poolId];
        _stake.currentEpochBalance += uint96(stake);
        _stake.nextEpochBalance += uint96(stake);
        _stake.currentEpoch = uint32(currentEpoch);
        _withdrawAndSyncDelegatorRewards(
            poolId,
            delegator
        );
    }

    /// @dev Create and delegate stake that will occur in the next epoch
    ///      (normal behavior).
    ///      Also withdraws pending rewards.
    function delegateStake(
        address delegator,
        bytes32 poolId,
        uint256 stake
    )
        external
    {
        _withdrawAndSyncDelegatorRewards(
            poolId,
            delegator
        );
        IStructs.StoredBalance storage _stake = _delegatedStakeToPoolByOwner[delegator][poolId];
        if (_stake.currentEpoch < currentEpoch) {
            _stake.currentEpochBalance = _stake.nextEpochBalance;
        }
        _stake.nextEpochBalance += uint96(stake);
        _stake.currentEpoch = uint32(currentEpoch);
    }

    /// @dev Clear stake that will occur in the next epoch
    ///      (normal behavior).
    ///      Also withdraws pending rewards.
    function undelegateStake(
        address delegator,
        bytes32 poolId,
        uint256 stake
    )
        external
    {
        _withdrawAndSyncDelegatorRewards(
            poolId,
            delegator
        );
        IStructs.StoredBalance storage _stake = _delegatedStakeToPoolByOwner[delegator][poolId];
        if (_stake.currentEpoch < currentEpoch) {
            _stake.currentEpochBalance = _stake.nextEpochBalance;
        }
        _stake.nextEpochBalance -= uint96(stake);
        _stake.currentEpoch = uint32(currentEpoch);
    }

    // solhint-disable no-simple-event-func-name
    /// @dev Overridden to realize `unfinalizedPoolRewardsByEpoch` in
    ///      the current epoch and emit a event,
    function finalizePool(bytes32 poolId)
        external
    {
        UnfinalizedPoolReward memory reward = unfinalizedPoolRewardsByEpoch[currentEpoch][poolId];
        delete unfinalizedPoolRewardsByEpoch[currentEpoch][poolId];

        _setOperatorShare(poolId, reward.operatorReward, reward.membersReward);

        uint256 totalRewards = reward.operatorReward + reward.membersReward;
        uint256 membersStake = reward.membersStake;
        (uint256 operatorReward, uint256 membersReward) =
            _syncPoolRewards(poolId, totalRewards, membersStake);
        emit FinalizePool(poolId, operatorReward, membersReward, membersStake);
    }

    /// @dev Overridden to use unfinalizedPoolRewardsByEpoch.
    function _getUnfinalizedPoolRewards(bytes32 poolId)
        internal
        view
        returns (
            uint256 totalReward,
            uint256 membersStake
        )
    {
        UnfinalizedPoolReward storage reward = unfinalizedPoolRewardsByEpoch[currentEpoch][poolId];
        totalReward = reward.operatorReward + reward.membersReward;
        membersStake = reward.membersStake;
    }

    /// @dev Set the operator share of a pool based on reward ratios.
    function _setOperatorShare(
        bytes32 poolId,
        uint256 operatorReward,
        uint256 membersReward
    )
        private
    {
        uint32 operatorShare = 0;
        uint256 totalReward = operatorReward + membersReward;
        if (totalReward != 0) {
            operatorShare = uint32(
                operatorReward * PPM_DENOMINATOR / totalReward
            );
        }
        _poolById[poolId].operatorShare = operatorShare;
    }

}

File 45 of 58 : TestStakingNoWETH.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;
pragma experimental ABIEncoderV2;

import "../src/Staking.sol";


// solhint-disable no-empty-blocks,no-simple-event-func-name
/// @dev A version of the staking contract with WETH-related functions
///      overridden to do nothing.
contract TestStakingNoWETH is
    Staking
{
    event Transfer(
        address indexed _from,
        address indexed _to,
        uint256 _value
    );

    function transfer(address to, uint256 amount)
        external
        returns (bool)
    {
        emit Transfer(address(this), to, amount);
        return true;
    }

    function getWethContract()
        public
        view
        returns (IEtherToken)
    {
        return IEtherToken(address(this));
    }

    function _wrapEth()
        internal
    {}

    function _getAvailableWethBalance()
        internal
        view
        returns (uint256)
    {
        return address(this).balance;
    }
}

File 46 of 58 : TestExchangeManager.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;
pragma experimental ABIEncoderV2;

import "../src/Staking.sol";


contract TestExchangeManager is
    Staking
{
    function setValidExchange(address exchange)
        external
    {
        validExchanges[exchange] = true;
    }

    function onlyExchangeFunction()
        external
        view
        onlyExchange
        returns (bool)
    {
        return true;
    }
}

File 47 of 58 : TestFinalizer.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;
pragma experimental ABIEncoderV2;

import "../src/interfaces/IStructs.sol";
import "../src/libs/LibCobbDouglas.sol";
import "./TestStakingNoWETH.sol";


contract TestFinalizer is
    TestStakingNoWETH
{
    event DepositStakingPoolRewards(
        bytes32 poolId,
        uint256 reward,
        uint256 membersStake
    );

    struct UnfinalizedPoolReward {
        uint256 totalReward;
        uint256 membersStake;
    }

    struct FinalizedPoolRewards {
        uint256 operatorReward;
        uint256 membersReward;
        uint256 membersStake;
    }

    address payable private _operatorRewardsReceiver;
    address payable private _membersRewardsReceiver;
    mapping (bytes32 => uint32) private _operatorSharesByPool;

    /// @param operatorRewardsReceiver The address to transfer rewards into when
    ///        a pool is finalized.
    constructor(
        address payable operatorRewardsReceiver,
        address payable membersRewardsReceiver
    )
        public
    {
        _addAuthorizedAddress(msg.sender);
        init();
        _operatorRewardsReceiver = operatorRewardsReceiver;
        _membersRewardsReceiver = membersRewardsReceiver;
        _removeAuthorizedAddressAtIndex(msg.sender, 0);
    }

    // this contract can receive ETH
    // solhint-disable no-empty-blocks
    function ()
        external
        payable
    {}

    /// @dev Activate a pool in the current epoch.
    function addActivePool(
        bytes32 poolId,
        uint32 operatorShare,
        uint256 feesCollected,
        uint256 membersStake,
        uint256 weightedStake
    )
        external
    {
        require(feesCollected > 0, "FEES_MUST_BE_NONZERO");
        uint256 currentEpoch_ = currentEpoch;
        IStructs.PoolStats memory poolStats = poolStatsByEpoch[poolId][currentEpoch_];
        require(poolStats.feesCollected == 0, "POOL_ALREADY_ADDED");
        _operatorSharesByPool[poolId] = operatorShare;
        poolStatsByEpoch[poolId][currentEpoch_] = IStructs.PoolStats({
            feesCollected: feesCollected,
            membersStake: membersStake,
            weightedStake: weightedStake
        });

        aggregatedStatsByEpoch[currentEpoch_].totalFeesCollected += feesCollected;
        aggregatedStatsByEpoch[currentEpoch_].totalWeightedStake += weightedStake;
        aggregatedStatsByEpoch[currentEpoch_].numPoolsToFinalize += 1;
    }

    /// @dev Drain the balance of this contract.
    function drainBalance()
        external
    {
        address(0).transfer(address(this).balance);
    }

    /// @dev Compute Cobb-Douglas.
    function cobbDouglas(
        uint256 totalRewards,
        uint256 ownerFees,
        uint256 totalFees,
        uint256 ownerStake,
        uint256 totalStake
    )
        external
        view
        returns (uint256 ownerRewards)
    {
        ownerRewards = LibCobbDouglas.cobbDouglas(
            totalRewards,
            ownerFees,
            totalFees,
            ownerStake,
            totalStake,
            cobbDouglasAlphaNumerator,
            cobbDouglasAlphaDenominator
        );
    }

    /// @dev Expose `_getUnfinalizedPoolReward()`
    function getUnfinalizedPoolRewards(bytes32 poolId)
        external
        view
        returns (UnfinalizedPoolReward memory reward)
    {
        (reward.totalReward, reward.membersStake) = _getUnfinalizedPoolRewards(
            poolId
        );
    }

    /// @dev Expose pool stats for the input epoch.
    function getPoolStatsFromEpoch(uint256 epoch, bytes32 poolId)
        external
        view
        returns (IStructs.PoolStats memory)
    {
        return poolStatsByEpoch[poolId][epoch];
    }

    function getAggregatedStatsForPreviousEpoch()
        external
        view
        returns (IStructs.AggregatedStats memory)
    {
        return aggregatedStatsByEpoch[currentEpoch - 1];
    }

    /// @dev Overridden to log and transfer to receivers.
    function _syncPoolRewards(
        bytes32 poolId,
        uint256 reward,
        uint256 membersStake
    )
        internal
        returns (uint256 operatorReward, uint256 membersReward)
    {
        uint32 operatorShare = _operatorSharesByPool[poolId];
        (operatorReward, membersReward) = _computePoolRewardsSplit(
            operatorShare,
            reward,
            membersStake
        );
        address(_operatorRewardsReceiver).transfer(operatorReward);
        address(_membersRewardsReceiver).transfer(membersReward);
        emit DepositStakingPoolRewards(poolId, reward, membersStake);
    }

    /// @dev Overriden to just increase the epoch counter.
    function _goToNextEpoch() internal {
        currentEpoch += 1;
    }
}

File 48 of 58 : TestMixinCumulativeRewards.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;
pragma experimental ABIEncoderV2;

import "./TestStaking.sol";


contract TestMixinCumulativeRewards is
    TestStaking
{

    constructor(
        address wethAddress,
        address zrxVaultAddress
    )
        public
        TestStaking(
            wethAddress,
            zrxVaultAddress
        )
    {
        _addAuthorizedAddress(msg.sender);
        init();
        _removeAuthorizedAddressAtIndex(msg.sender, 0);
    }

    /// @dev Exposes `_isCumulativeRewardSet`
    function isCumulativeRewardSet(IStructs.Fraction memory cumulativeReward)
        public
        pure
        returns (bool)
    {
        return _isCumulativeRewardSet(cumulativeReward);
    }

    /// @dev Exposes `_addCumulativeReward`
    function addCumulativeReward(
        bytes32 poolId,
        uint256 reward,
        uint256 stake
    )
        public
    {
        _addCumulativeReward(poolId, reward, stake);
    }

    /// @dev Exposes `_updateCumulativeReward`
    function updateCumulativeReward(bytes32 poolId)
        public
    {
        _updateCumulativeReward(poolId);
    }

    /// @dev Exposes _computeMemberRewardOverInterval
    function computeMemberRewardOverInterval(
        bytes32 poolId,
        uint256 memberStakeOverInterval,
        uint256 beginEpoch,
        uint256 endEpoch
    )
        public
        view
        returns (uint256 reward)
    {
        return _computeMemberRewardOverInterval(poolId, memberStakeOverInterval, beginEpoch, endEpoch);
    }

    /// @dev Increments current epoch by 1
    function incrementEpoch()
        public
    {
        currentEpoch += 1;
    }

    /// @dev Stores an arbitrary cumulative reward for a given epoch.
    ///      Also sets the `_cumulativeRewardsByPoolLastStored` to the input epoch.
    function storeCumulativeReward(
        bytes32 poolId,
        IStructs.Fraction memory cumulativeReward,
        uint256 epoch
    )
        public
    {
        _cumulativeRewardsByPool[poolId][epoch] = cumulativeReward;
        _cumulativeRewardsByPoolLastStored[poolId] = epoch;
    }

    /// @dev Returns the most recent cumulative reward for a given pool.
    function getMostRecentCumulativeReward(bytes32 poolId)
        public
        returns (IStructs.Fraction memory)
    {
        uint256 mostRecentEpoch = _cumulativeRewardsByPoolLastStored[poolId];
        return _cumulativeRewardsByPool[poolId][mostRecentEpoch];
    }

    /// @dev Returns the raw cumulative reward for a given pool in an epoch.
    ///      This is considered "raw" because the internal implementation
    ///      (_getCumulativeRewardAtEpochRaw) will query other state variables
    ///      to determine the most accurate cumulative reward for a given epoch.
    function getCumulativeRewardAtEpochRaw(bytes32 poolId, uint256 epoch)
        public
        returns (IStructs.Fraction memory)
    {
        return  _cumulativeRewardsByPool[poolId][epoch];
    }
}

File 49 of 58 : TestMixinScheduler.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;
pragma experimental ABIEncoderV2;

import "./TestStaking.sol";


contract TestMixinScheduler is
    TestStaking
{
    uint256 public testDeployedTimestamp;

    event GoToNextEpochTestInfo(
        uint256 oldEpoch,
        uint256 blockTimestamp
    );

    constructor(
        address wethAddress,
        address zrxVaultAddress
    )
        public
        TestStaking(
            wethAddress,
            zrxVaultAddress
        )
    {
        _addAuthorizedAddress(msg.sender);
        init();
        _removeAuthorizedAddressAtIndex(msg.sender, 0);

        // Record time of deployment
        // solhint-disable-next-line not-rely-on-time
        testDeployedTimestamp = block.timestamp;
    }

    /// @dev Tests `_goToNextEpoch`.
    ///      Configures internal variables such taht `epochEndTime` will be
    ///      less-than, equal-to, or greater-than the block timestamp.
    /// @param epochEndTimeDelta Set to desired `epochEndTime - block.timestamp`
    function goToNextEpochTest(int256 epochEndTimeDelta)
        public
    {
        // solhint-disable-next-line not-rely-on-time
        uint256 blockTimestamp = block.timestamp;

        // Emit info used by client-side test code
        emit GoToNextEpochTestInfo(
            currentEpoch,
            blockTimestamp
        );

        // (i) In `_goToNextEpoch` we compute:
        //     `epochEndTime = currentEpochStartTimeInSeconds + epochDurationInSeconds`
        // (ii) We want adjust internal state such that:
        //      `epochEndTime - block.timestamp = epochEndTimeDelta`, or
        //      `currentEpochStartTimeInSeconds + epochDurationInSeconds - block.timestamp = epochEndTimeDelta`
        //
        // To do this, we:
        //  (i) Set `epochDurationInSeconds` to a constant value of 1, and
        //  (ii) Rearrange the eqn above to get:
        //      `currentEpochStartTimeInSeconds = epochEndTimeDelta + block.timestamp - epochDurationInSeconds`
        epochDurationInSeconds = 1;
        currentEpochStartTimeInSeconds =
            uint256(epochEndTimeDelta + int256(blockTimestamp) - int256(epochDurationInSeconds));

        // Test internal function
        _goToNextEpoch();
    }

    /// @dev Tests `_initMixinScheduler`
    /// @param _currentEpochStartTimeInSeconds Sets `currentEpochStartTimeInSeconds` to this value before test.
    function initMixinSchedulerTest(uint256 _currentEpochStartTimeInSeconds)
        public
    {
        currentEpochStartTimeInSeconds = _currentEpochStartTimeInSeconds;
        _initMixinScheduler();
    }
}

File 50 of 58 : TestMixinStake.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;
pragma experimental ABIEncoderV2;

import "../src/interfaces/IStructs.sol";
import "./TestStakingNoWETH.sol";


contract TestMixinStake is
    TestStakingNoWETH
{
    event ZrxVaultDepositFrom(
        address staker,
        uint256 amount
    );

    event ZrxVaultWithdrawFrom(
        address staker,
        uint256 amount
    );

    event MoveStakeStorage(
        bytes32 fromBalanceSlot,
        bytes32 toBalanceSlot,
        uint256 amount
    );

    event IncreaseCurrentAndNextBalance(
        bytes32 balanceSlot,
        uint256 amount
    );

    event DecreaseCurrentAndNextBalance(
        bytes32 balanceSlot,
        uint256 amount
    );

    event IncreaseNextBalance(
        bytes32 balanceSlot,
        uint256 amount
    );

    event DecreaseNextBalance(
        bytes32 balanceSlot,
        uint256 amount
    );

    event WithdrawAndSyncDelegatorRewards(
        bytes32 poolId,
        address delegator
    );

    /// @dev Advance the epoch counter.
    function advanceEpoch() external {
        currentEpoch += 1;
    }

    /// @dev `IZrxVault.depositFrom`
    function depositFrom(address staker, uint256 amount) external {
        emit ZrxVaultDepositFrom(staker, amount);
    }

    /// @dev `IZrxVault.withdrawFrom`
    function withdrawFrom(address staker, uint256 amount) external {
        emit ZrxVaultWithdrawFrom(staker, amount);
    }

    function getDelegatedStakeByPoolIdSlot(bytes32 poolId)
        external
        view
        returns (bytes32 slot)
    {
        return _getPtrSlot(_delegatedStakeByPoolId[poolId]);
    }

    function getDelegatedStakeToPoolByOwnerSlot(bytes32 poolId, address staker)
        external
        view
        returns (bytes32 slot)
    {
        return _getPtrSlot(_delegatedStakeToPoolByOwner[staker][poolId]);
    }

    function getGlobalStakeByStatusSlot(IStructs.StakeStatus status)
        external
        view
        returns (bytes32 slot)
    {
        return _getPtrSlot(_globalStakeByStatus[uint8(status)]);
    }

    function getOwnerStakeByStatusSlot(address owner, IStructs.StakeStatus status)
        external
        view
        returns (bytes32 slot)
    {
        return _getPtrSlot(_ownerStakeByStatus[uint8(status)][owner]);
    }

    /// @dev Set `_ownerStakeByStatus`
    function setOwnerStakeByStatus(
        address owner,
        IStructs.StakeStatus status,
        IStructs.StoredBalance memory stake
    )
        public
    {
        _ownerStakeByStatus[uint8(status)][owner] = stake;
    }

    /// @dev Overridden to use this contract as the ZRX vault.
    function getZrxVault()
        public
        view
        returns (IZrxVault zrxVault)
    {
        return IZrxVault(address(this));
    }

    /// @dev Overridden to only emit an event.
    function _withdrawAndSyncDelegatorRewards(
        bytes32 poolId,
        address member
    )
        internal
    {
        emit WithdrawAndSyncDelegatorRewards(poolId, member);
    }

    /// @dev Overridden to only emit an event.
    function _moveStake(
        IStructs.StoredBalance storage fromPtr,
        IStructs.StoredBalance storage toPtr,
        uint256 amount
    )
        internal
    {
        emit MoveStakeStorage(
            _getPtrSlot(fromPtr),
            _getPtrSlot(toPtr),
            amount
        );
    }

    /// @dev Overridden to only emit an event.
    function _increaseCurrentAndNextBalance(
        IStructs.StoredBalance storage balancePtr,
        uint256 amount
    )
        internal
    {
        emit IncreaseCurrentAndNextBalance(
            _getPtrSlot(balancePtr),
            amount
        );
    }

    /// @dev Overridden to only emit an event.
    function _decreaseCurrentAndNextBalance(
        IStructs.StoredBalance storage balancePtr,
        uint256 amount
    )
        internal
    {
        emit DecreaseCurrentAndNextBalance(
            _getPtrSlot(balancePtr),
            amount
        );
    }

    /// @dev Overridden to only emit an event.
    function _increaseNextBalance(
        IStructs.StoredBalance storage balancePtr,
        uint256 amount
    )
        internal
    {
        emit IncreaseNextBalance(
            _getPtrSlot(balancePtr),
            amount
        );
    }

    /// @dev Overridden to only emit an event.
    function _decreaseNextBalance(
        IStructs.StoredBalance storage balancePtr,
        uint256 amount
    )
        internal
    {
        emit DecreaseNextBalance(
            _getPtrSlot(balancePtr),
            amount
        );
    }

    /// @dev Overridden to just return the input.
    function _loadCurrentBalance(IStructs.StoredBalance storage balancePtr)
        internal
        view
        returns (IStructs.StoredBalance memory balance)
    {
        balance = balancePtr;
    }

    /// @dev Throws if poolId == 0x0
    function _assertStakingPoolExists(bytes32 poolId)
        internal
        view
    {
        require(poolId != bytes32(0), "INVALID_POOL");
    }

    // solhint-disable-next-line
    function _getPtrSlot(IStructs.StoredBalance storage ptr)
        private
        pure
        returns (bytes32 offset)
    {
        assembly {
            offset := ptr_slot
        }
    }
}

File 51 of 58 : TestMixinStakeBalances.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;
pragma experimental ABIEncoderV2;

import "../src/interfaces/IStructs.sol";
import "./TestStakingNoWETH.sol";


contract TestMixinStakeBalances is
    TestStakingNoWETH
{
    uint256 private _balanceOfZrxVault;
    mapping (address => uint256) private _zrxBalanceOf;

    function setBalanceOfZrxVault(uint256 balance)
        external
    {
        _balanceOfZrxVault = balance;
    }

    function setZrxBalanceOf(address staker, uint256 balance)
        external
    {
        _zrxBalanceOf[staker] = balance;
    }

    /// @dev `IZrxVault.balanceOfZrxVault`
    function balanceOfZrxVault()
        external
        view
        returns (uint256)
    {
        return _balanceOfZrxVault;
    }

    /// @dev `IZrxVault.balanceOf`
    function balanceOf(address staker)
        external
        view
        returns (uint256)
    {
        return _zrxBalanceOf[staker];
    }

    /// @dev Set `_ownerStakeByStatus`
    function setOwnerStakeByStatus(
        address owner,
        IStructs.StakeStatus status,
        IStructs.StoredBalance memory stake
    )
        public
    {
        _ownerStakeByStatus[uint8(status)][owner] = stake;
    }

    /// @dev Set `_delegatedStakeToPoolByOwner`
    function setDelegatedStakeToPoolByOwner(
        address owner,
        bytes32 poolId,
        IStructs.StoredBalance memory stake
    )
        public
    {
        _delegatedStakeToPoolByOwner[owner][poolId] = stake;
    }

    /// @dev Set `_delegatedStakeByPoolId`
    function setDelegatedStakeByPoolId(
        bytes32 poolId,
        IStructs.StoredBalance memory stake
    )
        public
    {
        _delegatedStakeByPoolId[poolId] = stake;
    }

    /// @dev Set `_globalStakeByStatus`
    function setGlobalStakeByStatus(
        IStructs.StakeStatus status,
        IStructs.StoredBalance memory stake
    )
        public
    {
        _globalStakeByStatus[uint8(status)] = stake;
    }

    /// @dev Overridden to use this contract as the ZRX vault.
    function getZrxVault()
        public
        view
        returns (IZrxVault zrxVault)
    {
        return IZrxVault(address(this));
    }

    /// @dev Overridden to just return the input with the epoch incremented.
    function _loadCurrentBalance(IStructs.StoredBalance storage balancePtr)
        internal
        view
        returns (IStructs.StoredBalance memory balance)
    {
        balance = balancePtr;
        balance.currentEpoch += 1;
    }
}

File 52 of 58 : TestMixinStakingPool.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;
pragma experimental ABIEncoderV2;

import "../src/interfaces/IStructs.sol";
import "./TestStakingNoWETH.sol";


contract TestMixinStakingPool is
    TestStakingNoWETH
{
    function setLastPoolId(bytes32 poolId)
        external
    {
        lastPoolId = poolId;
    }

    function setPoolIdByMaker(bytes32 poolId, address maker)
        external
    {
        poolIdByMaker[maker] = poolId;
    }

    // solhint-disable no-empty-blocks
    function testOnlyStakingPoolOperatorModifier(bytes32 poolId)
        external
        view
        onlyStakingPoolOperator(poolId)
    {}

    function setPoolById(bytes32 poolId, IStructs.Pool memory pool)
        public
    {
        _poolById[poolId] = pool;
    }
}

File 53 of 58 : TestMixinStakingPoolRewards.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;
pragma experimental ABIEncoderV2;

import "../src/interfaces/IStructs.sol";
import "./TestStakingNoWETH.sol";


contract TestMixinStakingPoolRewards is
    TestStakingNoWETH
{
    // solhint-disable no-simple-event-func-name
    event UpdateCumulativeReward(
        bytes32 poolId
    );

    event WithdrawAndSyncDelegatorRewards(
        bytes32 poolId,
        address delegator
    );

    struct UnfinalizedPoolReward {
        uint256 reward;
        uint256 membersStake;
    }

    constructor() public {
        _addAuthorizedAddress(msg.sender);
        init();
        _removeAuthorizedAddressAtIndex(msg.sender, 0);
    }

    // Rewards returned by `_computeMemberRewardOverInterval()`, indexed
    // by `_getMemberRewardOverIntervalHash()`.
    mapping (bytes32 => uint256) private _memberRewardsOverInterval;
    // Rewards returned by `_getUnfinalizedPoolRewards()`, indexed by pool ID.
    mapping (bytes32 => UnfinalizedPoolReward) private _unfinalizedPoolRewards;

    // Set pool `rewardsByPoolId`.
    function setPoolRewards(
        bytes32 poolId,
        uint256 _rewardsByPoolId
    )
        external
    {
        rewardsByPoolId[poolId] = _rewardsByPoolId;
    }

    // Set `wethReservedForPoolRewards`.
    function setWethReservedForPoolRewards(
        uint256 _wethReservedForPoolRewards
    )
        external
    {
        wethReservedForPoolRewards = _wethReservedForPoolRewards;
    }

    // Set the rewards returned by a call to `_computeMemberRewardOverInterval()`.
    function setMemberRewardsOverInterval(
        bytes32 poolId,
        uint256 memberStakeOverInterval,
        uint256 beginEpoch,
        uint256 endEpoch,
        uint256 reward
    )
        external
    {
        bytes32 rewardHash = _getMemberRewardOverIntervalHash(
            poolId,
            memberStakeOverInterval,
            beginEpoch,
            endEpoch
        );
        _memberRewardsOverInterval[rewardHash] = reward;
    }

    // Set the rewards returned by `_getUnfinalizedPoolRewards()`.
    function setUnfinalizedPoolRewards(
        bytes32 poolId,
        uint256 reward,
        uint256 membersStake
    )
        external
    {
        _unfinalizedPoolRewards[poolId] = UnfinalizedPoolReward(
            reward,
            membersStake
        );
    }

    // Set `currentEpoch`.
    function setCurrentEpoch(uint256 epoch) external {
        currentEpoch = epoch;
    }

    // Expose `_syncPoolRewards()` for testing.
    function syncPoolRewards(
        bytes32 poolId,
        uint256 reward,
        uint256 membersStake
    )
        external
        returns (uint256 operatorReward, uint256 membersReward)
    {
        return _syncPoolRewards(poolId, reward, membersStake);
    }

    // Expose `_withdrawAndSyncDelegatorRewards()` for testing.
    function withdrawAndSyncDelegatorRewards(
        bytes32 poolId,
        address member
    )
        external
    {
        return _withdrawAndSyncDelegatorRewards(
            poolId,
            member
        );
    }

    // Expose `_computePoolRewardsSplit()` for testing.
    function computePoolRewardsSplit(
        uint32 operatorShare,
        uint256 totalReward,
        uint256 membersStake
    )
        external
        pure
        returns (uint256 operatorReward, uint256 membersReward)
    {
        return _computePoolRewardsSplit(
            operatorShare,
            totalReward,
            membersStake
        );
    }

    // Access `_delegatedStakeToPoolByOwner`
    function delegatedStakeToPoolByOwner(address member, bytes32 poolId)
        external
        view
        returns (IStructs.StoredBalance memory balance)
    {
        return _delegatedStakeToPoolByOwner[member][poolId];
    }

    // Set `_delegatedStakeToPoolByOwner`
    function setDelegatedStakeToPoolByOwner(
        address member,
        bytes32 poolId,
        IStructs.StoredBalance memory balance
    )
        public
    {
        _delegatedStakeToPoolByOwner[member][poolId] = balance;
    }

    // Set `_poolById`.
    function setPool(
        bytes32 poolId,
        IStructs.Pool memory pool
    )
        public
    {
        _poolById[poolId] = pool;
    }

    // Overridden to emit an event.
    function _withdrawAndSyncDelegatorRewards(
        bytes32 poolId,
        address member
    )
        internal
    {
        emit WithdrawAndSyncDelegatorRewards(poolId, member);
        return MixinStakingPoolRewards._withdrawAndSyncDelegatorRewards(
            poolId,
            member
        );
    }

    // Overridden to use `_memberRewardsOverInterval`
    function _computeMemberRewardOverInterval(
        bytes32 poolId,
        uint256 memberStakeOverInterval,
        uint256 beginEpoch,
        uint256 endEpoch
    )
        internal
        view
        returns (uint256 reward)
    {
        bytes32 rewardHash = _getMemberRewardOverIntervalHash(
            poolId,
            memberStakeOverInterval,
            beginEpoch,
            endEpoch
        );
        return _memberRewardsOverInterval[rewardHash];
    }

    // Overridden to use `_unfinalizedPoolRewards`
    function _getUnfinalizedPoolRewards(
        bytes32 poolId
    )
        internal
        view
        returns (uint256 reward, uint256 membersStake)
    {
        (reward, membersStake) = (
            _unfinalizedPoolRewards[poolId].reward,
            _unfinalizedPoolRewards[poolId].membersStake
        );
    }

    // Overridden to just increase `currentEpoch`.
    function _loadCurrentBalance(IStructs.StoredBalance storage balancePtr)
        internal
        view
        returns (IStructs.StoredBalance memory balance)
    {
        balance = balancePtr;
        balance.currentEpoch += 1;
    }

    // Overridden to revert if a pool has unfinalized rewards.
    function _assertPoolFinalizedLastEpoch(bytes32 poolId)
        internal
        view
    {
        require(
            _unfinalizedPoolRewards[poolId].membersStake == 0,
            "POOL_NOT_FINALIZED"
        );
    }

    // Overridden to just emit an event.
    function _updateCumulativeReward(bytes32 poolId)
        internal
    {
        emit UpdateCumulativeReward(poolId);
    }

    // Compute a hash to index `_memberRewardsOverInterval`
    function _getMemberRewardOverIntervalHash(
        bytes32 poolId,
        uint256 memberStakeOverInterval,
        uint256 beginEpoch,
        uint256 endEpoch
    )
        private
        pure
        returns (bytes32 rewardHash)
    {
        return keccak256(
            abi.encode(
                poolId,
                memberStakeOverInterval,
                beginEpoch,
                endEpoch
            )
        );
    }
}

File 54 of 58 : TestProtocolFees.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;
pragma experimental ABIEncoderV2;

import "../src/interfaces/IStructs.sol";
import "./TestStakingNoWETH.sol";


contract TestProtocolFees is
    TestStakingNoWETH
{
    struct TestPool {
        uint96 operatorStake;
        uint96 membersStake;
        mapping(address => bool) isMaker;
    }

    event ERC20ProxyTransferFrom(
        address from,
        address to,
        uint256 amount
    );

    mapping(bytes32 => TestPool) private _testPools;
    mapping(address => bytes32) private _makersToTestPoolIds;

    constructor(address exchangeAddress) public {
        _addAuthorizedAddress(msg.sender);
        init();
        validExchanges[exchangeAddress] = true;
        _removeAuthorizedAddressAtIndex(msg.sender, 0);
    }

    function advanceEpoch()
        external
    {
        currentEpoch += 1;
    }

    /// @dev Create a test pool.
    function createTestPool(
        bytes32 poolId,
        uint96 operatorStake,
        uint96 membersStake,
        address[] calldata makerAddresses
    )
        external
    {
        TestPool storage pool = _testPools[poolId];
        pool.operatorStake = operatorStake;
        pool.membersStake = membersStake;
        for (uint256 i = 0; i < makerAddresses.length; ++i) {
            pool.isMaker[makerAddresses[i]] = true;
            _makersToTestPoolIds[makerAddresses[i]] = poolId;
            poolIdByMaker[makerAddresses[i]] = poolId;
        }
    }

    /// @dev The ERC20Proxy `transferFrom()` function.
    function transferFrom(
        address from,
        address to,
        uint256 amount
    )
        external
        returns (bool)
    {
        emit ERC20ProxyTransferFrom(from, to, amount);
        return true;
    }

    function getAggregatedStatsForCurrentEpoch()
        external
        view
        returns (IStructs.AggregatedStats memory)
    {
        return aggregatedStatsByEpoch[currentEpoch];
    }

    /// @dev Overridden to use test pools.
    function getStakingPoolIdOfMaker(address makerAddress)
        public
        view
        returns (bytes32)
    {
        return _makersToTestPoolIds[makerAddress];
    }

    /// @dev Overridden to use test pools.
    function getTotalStakeDelegatedToPool(bytes32 poolId)
        public
        view
        returns (IStructs.StoredBalance memory balance)
    {
        TestPool memory pool = _testPools[poolId];
        uint96 stake = pool.operatorStake + pool.membersStake;
        return IStructs.StoredBalance({
            currentEpoch: currentEpoch.downcastToUint64(),
            currentEpochBalance: stake,
            nextEpochBalance: stake
        });
    }

    /// @dev Overridden to use test pools.
    function getStakeDelegatedToPoolByOwner(address, bytes32 poolId)
        public
        view
        returns (IStructs.StoredBalance memory balance)
    {
        TestPool memory pool = _testPools[poolId];
        return IStructs.StoredBalance({
            currentEpoch: currentEpoch.downcastToUint64(),
            currentEpochBalance: pool.operatorStake,
            nextEpochBalance: pool.operatorStake
        });
    }

    function getWethContract()
        public
        view
        returns (IEtherToken wethContract)
    {
        return IEtherToken(address(this));
    }
}

File 55 of 58 : TestProxyDestination.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;
pragma experimental ABIEncoderV2;

import "../src/Staking.sol";


contract TestProxyDestination is
    Staking
{
    // Init will revert if this flag is set to `true`
    bool public initFailFlag;

    /// @dev Emitted when `init` is called
    event InitCalled(
        bool initCalled
    );

    /// @dev returns the input string
    function echo(string calldata val)
        external
        returns (string memory)
    {
        return val;
    }

    /// @dev Just a function that'll do some math on input
    function doMath(uint256 a, uint256 b)
        external
        returns (uint256 sum, uint256 difference)
    {
        return (
            a + b,
            a - b
        );
    }

    /// @dev reverts with "Goodbye, World!"
    function die()
        external
    {
        revert("Goodbye, World!");
    }

    /// @dev Called when attached to the StakingProxy.
    ///      Reverts if `initFailFlag` is set, otherwise
    ///      sets storage params and emits `InitCalled`.
    function init()
        public
    {
        if (initFailFlag) {
            revert("INIT_FAIL_FLAG_SET");
        }

        // Set params such that they'll pass `StakingProxy.assertValidStorageParams`
        epochDurationInSeconds = 5 days;
        cobbDouglasAlphaNumerator = 1;
        cobbDouglasAlphaDenominator = 1;
        rewardDelegatedStakeWeight = PPM_DENOMINATOR;
        minimumPoolStake = 100;

        // Emit event to notify that `init` was called
        emit InitCalled(true);
    }
}

File 56 of 58 : TestStorageLayoutAndConstants.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;
pragma experimental ABIEncoderV2;

import "@0x/contracts-asset-proxy/contracts/src/interfaces/IAssetData.sol";
import "@0x/contracts-utils/contracts/src/LibBytes.sol";
import "../src/Staking.sol";


contract TestStorageLayoutAndConstants is
    Staking
{
    using LibBytes for bytes;

    /// @dev Construction will fail if the storage layout or the deployment constants are incompatible
    ///      with the V1 staking proxy.
    constructor() public {
        _assertDeploymentConstants();
        _assertStorageLayout();
    }

    /// @dev This function will fail if the deployment constants change to the point where they
    ///      are considered "invalid".
    function _assertDeploymentConstants()
        internal
        view
    {
        require(
            address(getWethContract()) != address(0),
            "WETH_MUST_BE_SET"
        );

        require(
            address(getZrxVault()) != address(0),
            "ZRX_VAULT_MUST_BE_SET"
        );
    }

    /// @dev This function will fail if the storage layout of this contract deviates from
    ///      the original staking contract's storage. The use of this function provides assurance
    ///      that regressions from the original storage layout will not occur.
    function _assertStorageLayout()
        internal
        pure
    {
        assembly {
            let slot := 0x0
            let offset := 0x0

            /// Ownable

            assertSlotAndOffset(
                owner_slot,
                owner_offset,
                slot,
                offset
            )
            slot := add(slot, 0x1)

            /// Authorizable

            assertSlotAndOffset(
                authorized_slot,
                authorized_offset,
                slot,
                offset
            )
            slot := add(slot, 0x1)

            assertSlotAndOffset(
                authorities_slot,
                authorities_offset,
                slot,
                offset
            )
            slot := add(slot, 0x1)

            /// MixinStorage

            assertSlotAndOffset(
                stakingContract_slot,
                stakingContract_offset,
                slot,
                offset
            )
            slot := add(slot, 0x1)

            assertSlotAndOffset(
                _globalStakeByStatus_slot,
                _globalStakeByStatus_offset,
                slot,
                offset
            )
            slot := add(slot, 0x1)

            assertSlotAndOffset(
                _ownerStakeByStatus_slot,
                _ownerStakeByStatus_offset,
                slot,
                offset
            )
            slot := add(slot, 0x1)

            assertSlotAndOffset(
                _delegatedStakeToPoolByOwner_slot,
                _delegatedStakeToPoolByOwner_offset,
                slot,
                offset
            )
            slot := add(slot, 0x1)

            assertSlotAndOffset(
                _delegatedStakeByPoolId_slot,
                _delegatedStakeByPoolId_offset,
                slot,
                offset
            )
            slot := add(slot, 0x1)

            assertSlotAndOffset(
                lastPoolId_slot,
                lastPoolId_offset,
                slot,
                offset
            )
            slot := add(slot, 0x1)

            assertSlotAndOffset(
                poolIdByMaker_slot,
                poolIdByMaker_offset,
                slot,
                offset
            )
            slot := add(slot, 0x1)

            assertSlotAndOffset(
                _poolById_slot,
                _poolById_offset,
                slot,
                offset
            )
            slot := add(slot, 0x1)

            assertSlotAndOffset(
                rewardsByPoolId_slot,
                rewardsByPoolId_offset,
                slot,
                offset
            )
            slot := add(slot, 0x1)

            assertSlotAndOffset(
                currentEpoch_slot,
                currentEpoch_offset,
                slot,
                offset
            )
            slot := add(slot, 0x1)

            assertSlotAndOffset(
                currentEpochStartTimeInSeconds_slot,
                currentEpochStartTimeInSeconds_offset,
                slot,
                offset
            )
            slot := add(slot, 0x1)

            assertSlotAndOffset(
                _cumulativeRewardsByPool_slot,
                _cumulativeRewardsByPool_offset,
                slot,
                offset
            )
            slot := add(slot, 0x1)

            assertSlotAndOffset(
                _cumulativeRewardsByPoolLastStored_slot,
                _cumulativeRewardsByPoolLastStored_offset,
                slot,
                offset
            )
            slot := add(slot, 0x1)

            assertSlotAndOffset(
                validExchanges_slot,
                validExchanges_offset,
                slot,
                offset
            )
            slot := add(slot, 0x1)

            assertSlotAndOffset(
                epochDurationInSeconds_slot,
                epochDurationInSeconds_offset,
                slot,
                offset
            )
            slot := add(slot, 0x1)

            assertSlotAndOffset(
                rewardDelegatedStakeWeight_slot,
                rewardDelegatedStakeWeight_offset,
                slot,
                offset
            )
            slot := add(slot, 0x1)

            assertSlotAndOffset(
                minimumPoolStake_slot,
                minimumPoolStake_offset,
                slot,
                offset
            )
            slot := add(slot, 0x1)

            assertSlotAndOffset(
                cobbDouglasAlphaNumerator_slot,
                cobbDouglasAlphaNumerator_offset,
                slot,
                offset
            )
            offset := add(offset, 0x4)

            // This number will be tightly packed into the previous values storage slot since
            // they are both `uint32`. Because of this tight packing, the offset of this value
            // must be 4, since the previous value is a 4 byte number.
            assertSlotAndOffset(
                cobbDouglasAlphaDenominator_slot,
                cobbDouglasAlphaDenominator_offset,
                slot,
                offset
            )
            slot := add(slot, 0x1)
            offset := 0x0

            assertSlotAndOffset(
                poolStatsByEpoch_slot,
                poolStatsByEpoch_offset,
                slot,
                offset
            )
            slot := add(slot, 0x1)

            assertSlotAndOffset(
                aggregatedStatsByEpoch_slot,
                aggregatedStatsByEpoch_offset,
                slot,
                offset
            )
            slot := add(slot, 0x1)

            assertSlotAndOffset(
                wethReservedForPoolRewards_slot,
                wethReservedForPoolRewards_offset,
                slot,
                offset
            )

            // This assembly function will assert that the actual values for `_slot` and `_offset` are
            // correct and will revert with a rich error if they are different than the expected values.
            function assertSlotAndOffset(
                actual_slot,
                actual_offset,
                expected_slot,
                expected_offset
            ) {
                // If expected_slot is not equal to actual_slot, revert with a rich error.
                if iszero(eq(expected_slot, actual_slot)) {
                    mstore(0x0, 0x213eb13400000000000000000000000000000000000000000000000000000000) // Rich error selector
                    mstore(0x4, 0x0)                                                                // Unexpected slot error code
                    mstore(0x24, expected_slot)                                                     // Expected slot
                    mstore(0x44, actual_slot)                                                       // Actual slot
                    revert(0x0, 0x64)
                }

                // If expected_offset is not equal to actual_offset, revert with a rich error.
                if iszero(eq(expected_offset, actual_offset)) {
                    mstore(0x0, 0x213eb13400000000000000000000000000000000000000000000000000000000) // Rich error selector
                    mstore(0x4, 0x1)                                                                // Unexpected offset error code
                    mstore(0x24, expected_offset)                                                   // Expected offset
                    mstore(0x44, actual_offset)                                                     // Actual offset
                    revert(0x0, 0x64)
                }
            }
        }
    }
}

File 57 of 58 : LibBytes.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;

import "./LibBytesRichErrors.sol";
import "./LibRichErrors.sol";


library LibBytes {

    using LibBytes for bytes;

    /// @dev Gets the memory address for a byte array.
    /// @param input Byte array to lookup.
    /// @return memoryAddress Memory address of byte array. This
    ///         points to the header of the byte array which contains
    ///         the length.
    function rawAddress(bytes memory input)
        internal
        pure
        returns (uint256 memoryAddress)
    {
        assembly {
            memoryAddress := input
        }
        return memoryAddress;
    }

    /// @dev Gets the memory address for the contents of a byte array.
    /// @param input Byte array to lookup.
    /// @return memoryAddress Memory address of the contents of the byte array.
    function contentAddress(bytes memory input)
        internal
        pure
        returns (uint256 memoryAddress)
    {
        assembly {
            memoryAddress := add(input, 32)
        }
        return memoryAddress;
    }

    /// @dev Copies `length` bytes from memory location `source` to `dest`.
    /// @param dest memory address to copy bytes to.
    /// @param source memory address to copy bytes from.
    /// @param length number of bytes to copy.
    function memCopy(
        uint256 dest,
        uint256 source,
        uint256 length
    )
        internal
        pure
    {
        if (length < 32) {
            // Handle a partial word by reading destination and masking
            // off the bits we are interested in.
            // This correctly handles overlap, zero lengths and source == dest
            assembly {
                let mask := sub(exp(256, sub(32, length)), 1)
                let s := and(mload(source), not(mask))
                let d := and(mload(dest), mask)
                mstore(dest, or(s, d))
            }
        } else {
            // Skip the O(length) loop when source == dest.
            if (source == dest) {
                return;
            }

            // For large copies we copy whole words at a time. The final
            // word is aligned to the end of the range (instead of after the
            // previous) to handle partial words. So a copy will look like this:
            //
            //  ####
            //      ####
            //          ####
            //            ####
            //
            // We handle overlap in the source and destination range by
            // changing the copying direction. This prevents us from
            // overwriting parts of source that we still need to copy.
            //
            // This correctly handles source == dest
            //
            if (source > dest) {
                assembly {
                    // We subtract 32 from `sEnd` and `dEnd` because it
                    // is easier to compare with in the loop, and these
                    // are also the addresses we need for copying the
                    // last bytes.
                    length := sub(length, 32)
                    let sEnd := add(source, length)
                    let dEnd := add(dest, length)

                    // Remember the last 32 bytes of source
                    // This needs to be done here and not after the loop
                    // because we may have overwritten the last bytes in
                    // source already due to overlap.
                    let last := mload(sEnd)

                    // Copy whole words front to back
                    // Note: the first check is always true,
                    // this could have been a do-while loop.
                    // solhint-disable-next-line no-empty-blocks
                    for {} lt(source, sEnd) {} {
                        mstore(dest, mload(source))
                        source := add(source, 32)
                        dest := add(dest, 32)
                    }

                    // Write the last 32 bytes
                    mstore(dEnd, last)
                }
            } else {
                assembly {
                    // We subtract 32 from `sEnd` and `dEnd` because those
                    // are the starting points when copying a word at the end.
                    length := sub(length, 32)
                    let sEnd := add(source, length)
                    let dEnd := add(dest, length)

                    // Remember the first 32 bytes of source
                    // This needs to be done here and not after the loop
                    // because we may have overwritten the first bytes in
                    // source already due to overlap.
                    let first := mload(source)

                    // Copy whole words back to front
                    // We use a signed comparisson here to allow dEnd to become
                    // negative (happens when source and dest < 32). Valid
                    // addresses in local memory will never be larger than
                    // 2**255, so they can be safely re-interpreted as signed.
                    // Note: the first check is always true,
                    // this could have been a do-while loop.
                    // solhint-disable-next-line no-empty-blocks
                    for {} slt(dest, dEnd) {} {
                        mstore(dEnd, mload(sEnd))
                        sEnd := sub(sEnd, 32)
                        dEnd := sub(dEnd, 32)
                    }

                    // Write the first 32 bytes
                    mstore(dest, first)
                }
            }
        }
    }

    /// @dev Returns a slices from a byte array.
    /// @param b The byte array to take a slice from.
    /// @param from The starting index for the slice (inclusive).
    /// @param to The final index for the slice (exclusive).
    /// @return result The slice containing bytes at indices [from, to)
    function slice(
        bytes memory b,
        uint256 from,
        uint256 to
    )
        internal
        pure
        returns (bytes memory result)
    {
        // Ensure that the from and to positions are valid positions for a slice within
        // the byte array that is being used.
        if (from > to) {
            LibRichErrors.rrevert(LibBytesRichErrors.InvalidByteOperationError(
                LibBytesRichErrors.InvalidByteOperationErrorCodes.FromLessThanOrEqualsToRequired,
                from,
                to
            ));
        }
        if (to > b.length) {
            LibRichErrors.rrevert(LibBytesRichErrors.InvalidByteOperationError(
                LibBytesRichErrors.InvalidByteOperationErrorCodes.ToLessThanOrEqualsLengthRequired,
                to,
                b.length
            ));
        }

        // Create a new bytes structure and copy contents
        result = new bytes(to - from);
        memCopy(
            result.contentAddress(),
            b.contentAddress() + from,
            result.length
        );
        return result;
    }

    /// @dev Returns a slice from a byte array without preserving the input.
    /// @param b The byte array to take a slice from. Will be destroyed in the process.
    /// @param from The starting index for the slice (inclusive).
    /// @param to The final index for the slice (exclusive).
    /// @return result The slice containing bytes at indices [from, to)
    /// @dev When `from == 0`, the original array will match the slice. In other cases its state will be corrupted.
    function sliceDestructive(
        bytes memory b,
        uint256 from,
        uint256 to
    )
        internal
        pure
        returns (bytes memory result)
    {
        // Ensure that the from and to positions are valid positions for a slice within
        // the byte array that is being used.
        if (from > to) {
            LibRichErrors.rrevert(LibBytesRichErrors.InvalidByteOperationError(
                LibBytesRichErrors.InvalidByteOperationErrorCodes.FromLessThanOrEqualsToRequired,
                from,
                to
            ));
        }
        if (to > b.length) {
            LibRichErrors.rrevert(LibBytesRichErrors.InvalidByteOperationError(
                LibBytesRichErrors.InvalidByteOperationErrorCodes.ToLessThanOrEqualsLengthRequired,
                to,
                b.length
            ));
        }

        // Create a new bytes structure around [from, to) in-place.
        assembly {
            result := add(b, from)
            mstore(result, sub(to, from))
        }
        return result;
    }

    /// @dev Pops the last byte off of a byte array by modifying its length.
    /// @param b Byte array that will be modified.
    /// @return The byte that was popped off.
    function popLastByte(bytes memory b)
        internal
        pure
        returns (bytes1 result)
    {
        if (b.length == 0) {
            LibRichErrors.rrevert(LibBytesRichErrors.InvalidByteOperationError(
                LibBytesRichErrors.InvalidByteOperationErrorCodes.LengthGreaterThanZeroRequired,
                b.length,
                0
            ));
        }

        // Store last byte.
        result = b[b.length - 1];

        assembly {
            // Decrement length of byte array.
            let newLen := sub(mload(b), 1)
            mstore(b, newLen)
        }
        return result;
    }

    /// @dev Tests equality of two byte arrays.
    /// @param lhs First byte array to compare.
    /// @param rhs Second byte array to compare.
    /// @return True if arrays are the same. False otherwise.
    function equals(
        bytes memory lhs,
        bytes memory rhs
    )
        internal
        pure
        returns (bool equal)
    {
        // Keccak gas cost is 30 + numWords * 6. This is a cheap way to compare.
        // We early exit on unequal lengths, but keccak would also correctly
        // handle this.
        return lhs.length == rhs.length && keccak256(lhs) == keccak256(rhs);
    }

    /// @dev Reads an address from a position in a byte array.
    /// @param b Byte array containing an address.
    /// @param index Index in byte array of address.
    /// @return address from byte array.
    function readAddress(
        bytes memory b,
        uint256 index
    )
        internal
        pure
        returns (address result)
    {
        if (b.length < index + 20) {
            LibRichErrors.rrevert(LibBytesRichErrors.InvalidByteOperationError(
                LibBytesRichErrors.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsTwentyRequired,
                b.length,
                index + 20 // 20 is length of address
            ));
        }

        // Add offset to index:
        // 1. Arrays are prefixed by 32-byte length parameter (add 32 to index)
        // 2. Account for size difference between address length and 32-byte storage word (subtract 12 from index)
        index += 20;

        // Read address from array memory
        assembly {
            // 1. Add index to address of bytes array
            // 2. Load 32-byte word from memory
            // 3. Apply 20-byte mask to obtain address
            result := and(mload(add(b, index)), 0xffffffffffffffffffffffffffffffffffffffff)
        }
        return result;
    }

    /// @dev Writes an address into a specific position in a byte array.
    /// @param b Byte array to insert address into.
    /// @param index Index in byte array of address.
    /// @param input Address to put into byte array.
    function writeAddress(
        bytes memory b,
        uint256 index,
        address input
    )
        internal
        pure
    {
        if (b.length < index + 20) {
            LibRichErrors.rrevert(LibBytesRichErrors.InvalidByteOperationError(
                LibBytesRichErrors.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsTwentyRequired,
                b.length,
                index + 20 // 20 is length of address
            ));
        }

        // Add offset to index:
        // 1. Arrays are prefixed by 32-byte length parameter (add 32 to index)
        // 2. Account for size difference between address length and 32-byte storage word (subtract 12 from index)
        index += 20;

        // Store address into array memory
        assembly {
            // The address occupies 20 bytes and mstore stores 32 bytes.
            // First fetch the 32-byte word where we'll be storing the address, then
            // apply a mask so we have only the bytes in the word that the address will not occupy.
            // Then combine these bytes with the address and store the 32 bytes back to memory with mstore.

            // 1. Add index to address of bytes array
            // 2. Load 32-byte word from memory
            // 3. Apply 12-byte mask to obtain extra bytes occupying word of memory where we'll store the address
            let neighbors := and(
                mload(add(b, index)),
                0xffffffffffffffffffffffff0000000000000000000000000000000000000000
            )

            // Make sure input address is clean.
            // (Solidity does not guarantee this)
            input := and(input, 0xffffffffffffffffffffffffffffffffffffffff)

            // Store the neighbors and address into memory
            mstore(add(b, index), xor(input, neighbors))
        }
    }

    /// @dev Reads a bytes32 value from a position in a byte array.
    /// @param b Byte array containing a bytes32 value.
    /// @param index Index in byte array of bytes32 value.
    /// @return bytes32 value from byte array.
    function readBytes32(
        bytes memory b,
        uint256 index
    )
        internal
        pure
        returns (bytes32 result)
    {
        if (b.length < index + 32) {
            LibRichErrors.rrevert(LibBytesRichErrors.InvalidByteOperationError(
                LibBytesRichErrors.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsThirtyTwoRequired,
                b.length,
                index + 32
            ));
        }

        // Arrays are prefixed by a 256 bit length parameter
        index += 32;

        // Read the bytes32 from array memory
        assembly {
            result := mload(add(b, index))
        }
        return result;
    }

    /// @dev Writes a bytes32 into a specific position in a byte array.
    /// @param b Byte array to insert <input> into.
    /// @param index Index in byte array of <input>.
    /// @param input bytes32 to put into byte array.
    function writeBytes32(
        bytes memory b,
        uint256 index,
        bytes32 input
    )
        internal
        pure
    {
        if (b.length < index + 32) {
            LibRichErrors.rrevert(LibBytesRichErrors.InvalidByteOperationError(
                LibBytesRichErrors.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsThirtyTwoRequired,
                b.length,
                index + 32
            ));
        }

        // Arrays are prefixed by a 256 bit length parameter
        index += 32;

        // Read the bytes32 from array memory
        assembly {
            mstore(add(b, index), input)
        }
    }

    /// @dev Reads a uint256 value from a position in a byte array.
    /// @param b Byte array containing a uint256 value.
    /// @param index Index in byte array of uint256 value.
    /// @return uint256 value from byte array.
    function readUint256(
        bytes memory b,
        uint256 index
    )
        internal
        pure
        returns (uint256 result)
    {
        result = uint256(readBytes32(b, index));
        return result;
    }

    /// @dev Writes a uint256 into a specific position in a byte array.
    /// @param b Byte array to insert <input> into.
    /// @param index Index in byte array of <input>.
    /// @param input uint256 to put into byte array.
    function writeUint256(
        bytes memory b,
        uint256 index,
        uint256 input
    )
        internal
        pure
    {
        writeBytes32(b, index, bytes32(input));
    }

    /// @dev Reads an unpadded bytes4 value from a position in a byte array.
    /// @param b Byte array containing a bytes4 value.
    /// @param index Index in byte array of bytes4 value.
    /// @return bytes4 value from byte array.
    function readBytes4(
        bytes memory b,
        uint256 index
    )
        internal
        pure
        returns (bytes4 result)
    {
        if (b.length < index + 4) {
            LibRichErrors.rrevert(LibBytesRichErrors.InvalidByteOperationError(
                LibBytesRichErrors.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsFourRequired,
                b.length,
                index + 4
            ));
        }

        // Arrays are prefixed by a 32 byte length field
        index += 32;

        // Read the bytes4 from array memory
        assembly {
            result := mload(add(b, index))
            // Solidity does not require us to clean the trailing bytes.
            // We do it anyway
            result := and(result, 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000)
        }
        return result;
    }

    /// @dev Writes a new length to a byte array.
    ///      Decreasing length will lead to removing the corresponding lower order bytes from the byte array.
    ///      Increasing length may lead to appending adjacent in-memory bytes to the end of the byte array.
    /// @param b Bytes array to write new length to.
    /// @param length New length of byte array.
    function writeLength(bytes memory b, uint256 length)
        internal
        pure
    {
        assembly {
            mstore(b, length)
        }
    }
}

File 58 of 58 : LibBytesRichErrors.sol
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

pragma solidity ^0.5.9;


library LibBytesRichErrors {

    enum InvalidByteOperationErrorCodes {
        FromLessThanOrEqualsToRequired,
        ToLessThanOrEqualsLengthRequired,
        LengthGreaterThanZeroRequired,
        LengthGreaterThanOrEqualsFourRequired,
        LengthGreaterThanOrEqualsTwentyRequired,
        LengthGreaterThanOrEqualsThirtyTwoRequired,
        LengthGreaterThanOrEqualsNestedBytesLengthRequired,
        DestinationLengthGreaterThanOrEqualSourceLengthRequired
    }

    // bytes4(keccak256("InvalidByteOperationError(uint8,uint256,uint256)"))
    bytes4 internal constant INVALID_BYTE_OPERATION_ERROR_SELECTOR =
        0x28006595;

    // solhint-disable func-name-mixedcase
    function InvalidByteOperationError(
        InvalidByteOperationErrorCodes errorCode,
        uint256 offset,
        uint256 required
    )
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            INVALID_BYTE_OPERATION_ERROR_SELECTOR,
            errorCode,
            offset,
            required
        );
    }
}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 1000000,
    "details": {
      "yul": true,
      "deduplicate": true,
      "cse": true,
      "constantOptimizer": true
    }
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "abi"
      ]
    }
  },
  "evmVersion": "constantinople",
  "remappings": [
    "@0x/contracts-erc20=/Users/amir/github/0xproject/0x-monorepo/contracts/staking/node_modules/@0x/contracts-erc20",
    "@0x/contracts-utils=/Users/amir/github/0xproject/0x-monorepo/contracts/staking/node_modules/@0x/contracts-utils",
    "@0x/contracts-exchange-libs=/Users/amir/github/0xproject/0x-monorepo/contracts/staking/node_modules/@0x/contracts-exchange-libs",
    "@0x/contracts-asset-proxy=/Users/amir/github/0xproject/0x-monorepo/contracts/staking/node_modules/@0x/contracts-asset-proxy"
  ]
}

Contract Security Audit

Contract ABI

[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"target","type":"address"},{"indexed":true,"internalType":"address","name":"caller","type":"address"}],"name":"AuthorizedAddressAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"target","type":"address"},{"indexed":true,"internalType":"address","name":"caller","type":"address"}],"name":"AuthorizedAddressRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"epoch","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"numPoolsToFinalize","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"rewardsAvailable","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"totalFeesCollected","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"totalWeightedStake","type":"uint256"}],"name":"EpochEnded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"epoch","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"rewardsPaid","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"rewardsRemaining","type":"uint256"}],"name":"EpochFinalized","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"exchangeAddress","type":"address"}],"name":"ExchangeAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"exchangeAddress","type":"address"}],"name":"ExchangeRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"makerAddress","type":"address"},{"indexed":true,"internalType":"bytes32","name":"poolId","type":"bytes32"}],"name":"MakerStakingPoolSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"staker","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint8","name":"fromStatus","type":"uint8"},{"indexed":true,"internalType":"bytes32","name":"fromPool","type":"bytes32"},{"indexed":false,"internalType":"uint8","name":"toStatus","type":"uint8"},{"indexed":true,"internalType":"bytes32","name":"toPool","type":"bytes32"}],"name":"MoveStake","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"poolId","type":"bytes32"},{"indexed":false,"internalType":"uint32","name":"oldOperatorShare","type":"uint32"},{"indexed":false,"internalType":"uint32","name":"newOperatorShare","type":"uint32"}],"name":"OperatorShareDecreased","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"epochDurationInSeconds","type":"uint256"},{"indexed":false,"internalType":"uint32","name":"rewardDelegatedStakeWeight","type":"uint32"},{"indexed":false,"internalType":"uint256","name":"minimumPoolStake","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"cobbDouglasAlphaNumerator","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"cobbDouglasAlphaDenominator","type":"uint256"}],"name":"ParamsSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"epoch","type":"uint256"},{"indexed":true,"internalType":"bytes32","name":"poolId","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"operatorReward","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"membersReward","type":"uint256"}],"name":"RewardsPaid","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"staker","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Stake","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"poolId","type":"bytes32"},{"indexed":false,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"uint32","name":"operatorShare","type":"uint32"}],"name":"StakingPoolCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"epoch","type":"uint256"},{"indexed":true,"internalType":"bytes32","name":"poolId","type":"bytes32"}],"name":"StakingPoolEarnedRewardsInEpoch","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"staker","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Unstake","type":"event"},{"constant":false,"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"addAuthorizedAddress","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"addExchangeAddress","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"aggregatedStatsByEpoch","outputs":[{"internalType":"uint256","name":"rewardsAvailable","type":"uint256"},{"internalType":"uint256","name":"numPoolsToFinalize","type":"uint256"},{"internalType":"uint256","name":"totalFeesCollected","type":"uint256"},{"internalType":"uint256","name":"totalWeightedStake","type":"uint256"},{"internalType":"uint256","name":"totalRewardsFinalized","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"authorities","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"authorized","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"cobbDouglasAlphaDenominator","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"cobbDouglasAlphaNumerator","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"poolId","type":"bytes32"},{"internalType":"address","name":"member","type":"address"}],"name":"computeRewardBalanceOfDelegator","outputs":[{"internalType":"uint256","name":"reward","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"poolId","type":"bytes32"}],"name":"computeRewardBalanceOfOperator","outputs":[{"internalType":"uint256","name":"reward","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"uint32","name":"operatorShare","type":"uint32"},{"internalType":"bool","name":"addOperatorAsMaker","type":"bool"}],"name":"createStakingPool","outputs":[{"internalType":"bytes32","name":"poolId","type":"bytes32"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"currentEpoch","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"currentEpochStartTimeInSeconds","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"poolId","type":"bytes32"},{"internalType":"uint32","name":"newOperatorShare","type":"uint32"}],"name":"decreaseStakingPoolOperatorShare","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"endEpoch","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"epochDurationInSeconds","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"poolId","type":"bytes32"}],"name":"finalizePool","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"getAuthorizedAddresses","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getCurrentEpochEarliestEndTimeInSeconds","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"enum IStructs.StakeStatus","name":"stakeStatus","type":"uint8"}],"name":"getGlobalStakeByStatus","outputs":[{"components":[{"internalType":"uint64","name":"currentEpoch","type":"uint64"},{"internalType":"uint96","name":"currentEpochBalance","type":"uint96"},{"internalType":"uint96","name":"nextEpochBalance","type":"uint96"}],"internalType":"struct IStructs.StoredBalance","name":"balance","type":"tuple"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"staker","type":"address"},{"internalType":"enum IStructs.StakeStatus","name":"stakeStatus","type":"uint8"}],"name":"getOwnerStakeByStatus","outputs":[{"components":[{"internalType":"uint64","name":"currentEpoch","type":"uint64"},{"internalType":"uint96","name":"currentEpochBalance","type":"uint96"},{"internalType":"uint96","name":"nextEpochBalance","type":"uint96"}],"internalType":"struct IStructs.StoredBalance","name":"balance","type":"tuple"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getParams","outputs":[{"internalType":"uint256","name":"_epochDurationInSeconds","type":"uint256"},{"internalType":"uint32","name":"_rewardDelegatedStakeWeight","type":"uint32"},{"internalType":"uint256","name":"_minimumPoolStake","type":"uint256"},{"internalType":"uint32","name":"_cobbDouglasAlphaNumerator","type":"uint32"},{"internalType":"uint32","name":"_cobbDouglasAlphaDenominator","type":"uint32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"staker","type":"address"},{"internalType":"bytes32","name":"poolId","type":"bytes32"}],"name":"getStakeDelegatedToPoolByOwner","outputs":[{"components":[{"internalType":"uint64","name":"currentEpoch","type":"uint64"},{"internalType":"uint96","name":"currentEpochBalance","type":"uint96"},{"internalType":"uint96","name":"nextEpochBalance","type":"uint96"}],"internalType":"struct IStructs.StoredBalance","name":"balance","type":"tuple"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"poolId","type":"bytes32"}],"name":"getStakingPool","outputs":[{"components":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"uint32","name":"operatorShare","type":"uint32"}],"internalType":"struct IStructs.Pool","name":"","type":"tuple"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"poolId","type":"bytes32"}],"name":"getStakingPoolStatsThisEpoch","outputs":[{"components":[{"internalType":"uint256","name":"feesCollected","type":"uint256"},{"internalType":"uint256","name":"weightedStake","type":"uint256"},{"internalType":"uint256","name":"membersStake","type":"uint256"}],"internalType":"struct IStructs.PoolStats","name":"","type":"tuple"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"staker","type":"address"}],"name":"getTotalStake","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"poolId","type":"bytes32"}],"name":"getTotalStakeDelegatedToPool","outputs":[{"components":[{"internalType":"uint64","name":"currentEpoch","type":"uint64"},{"internalType":"uint96","name":"currentEpochBalance","type":"uint96"},{"internalType":"uint96","name":"nextEpochBalance","type":"uint96"}],"internalType":"struct IStructs.StoredBalance","name":"balance","type":"tuple"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getWethContract","outputs":[{"internalType":"contract IEtherToken","name":"wethContract","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getZrxVault","outputs":[{"internalType":"contract IZrxVault","name":"zrxVault","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"init","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"poolId","type":"bytes32"}],"name":"joinStakingPoolAsMaker","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"lastPoolId","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"minimumPoolStake","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"components":[{"internalType":"enum IStructs.StakeStatus","name":"status","type":"uint8"},{"internalType":"bytes32","name":"poolId","type":"bytes32"}],"internalType":"struct IStructs.StakeInfo","name":"from","type":"tuple"},{"components":[{"internalType":"enum IStructs.StakeStatus","name":"status","type":"uint8"},{"internalType":"bytes32","name":"poolId","type":"bytes32"}],"internalType":"struct IStructs.StakeInfo","name":"to","type":"tuple"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"moveStake","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"makerAddress","type":"address"},{"internalType":"address","name":"payerAddress","type":"address"},{"internalType":"uint256","name":"protocolFee","type":"uint256"}],"name":"payProtocolFee","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"poolIdByMaker","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"poolStatsByEpoch","outputs":[{"internalType":"uint256","name":"feesCollected","type":"uint256"},{"internalType":"uint256","name":"weightedStake","type":"uint256"},{"internalType":"uint256","name":"membersStake","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"removeAuthorizedAddress","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"target","type":"address"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"removeAuthorizedAddressAtIndex","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"removeExchangeAddress","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"rewardDelegatedStakeWeight","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"rewardsByPoolId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"_epochDurationInSeconds","type":"uint256"},{"internalType":"uint32","name":"_rewardDelegatedStakeWeight","type":"uint32"},{"internalType":"uint256","name":"_minimumPoolStake","type":"uint256"},{"internalType":"uint32","name":"_cobbDouglasAlphaNumerator","type":"uint32"},{"internalType":"uint32","name":"_cobbDouglasAlphaDenominator","type":"uint32"}],"name":"setParams","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"stake","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"stakingContract","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"unstake","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"validExchanges","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"wethReservedForPoolRewards","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"poolId","type":"bytes32"}],"name":"withdrawDelegatorRewards","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]

6080604052600080546001600160a01b031916331790556156ac806100256000396000f3fe6080604052600436106103295760003560e01c80638da5cb5b116101a5578063bb7ef7e0116100ec578063e8eeb3f811610095578063f18765321161006f578063f1876532146108bf578063f252b7a1146108df578063f2fde38b146108ff578063ff691b111461091f57610329565b8063e8eeb3f814610875578063e907f0031461088a578063ee99205c146108aa57610329565b8063e0ee036e116100c6578063e0ee036e1461082b578063e1c7392a14610840578063e804d0a41461085557610329565b8063bb7ef7e0146107c9578063c18c9141146107e9578063d39de6e91461080957610329565b8063a694fc3a1161014e578063b3e3337911610128578063b3e3337914610769578063b510879f14610789578063b9181611146107a957610329565b8063a694fc3a1461071f578063b05315241461073f578063b2baa33e1461075457610329565b8063a26171e21161017f578063a26171e2146106e2578063a3b4a327146106f7578063a657e5791461070a57610329565b80638da5cb5b1461068d5780639ad26744146106a25780639c3ccc82146106c257610329565b80634bcc3f6711610274578063624a72321161021d57806370712939116101f757806370712939146106165780637667180814610636578063816667961461064b5780638a2e271a1461066d57610329565b8063624a7232146105cc57806363403801146105e157806368a7d6cd146105f657610329565b80635bd4ab731161024e5780635bd4ab73146105595780635d91121d146105865780635e615a6b146105a657610329565b80634bcc3f67146104f7578063587da0231461052457806358f6c7e31461053957610329565b80633c277fc5116102d657806344a6958b116102b057806344a6958b1461048a57806346b97959146104aa578063494503d4146104d757610329565b80633c277fc51461041b5780633e4ad7321461043d57806342f1181e1461046a57610329565b80632a94c279116103075780632a94c2791461039b5780632e17de78146103ca57806338229d93146103ea57610329565b806301e28d841461032e5780630b9663db146103505780631e7ff8f61461037b575b600080fd5b34801561033a57600080fd5b5061034e610349366004614fc7565b61093f565b005b34801561035c57600080fd5b50610365610a0d565b6040516103729190615327565b60405180910390f35b34801561038757600080fd5b50610365610396366004614fc7565b610b5a565b3480156103a757600080fd5b506103bb6103b63660046150db565b610bf4565b60405161037293929190615514565b3480156103d657600080fd5b5061034e6103e536600461509f565b610c20565b3480156103f657600080fd5b5061040a61040536600461509f565b610dd5565b604051610372959493929190615545565b34801561042757600080fd5b50610430610e04565b6040516103729190615224565b34801561044957600080fd5b5061045d61045836600461509f565b610e1c565b60405161037291906154d5565b34801561047657600080fd5b5061034e610485366004614fc7565b610e3b565b34801561049657600080fd5b5061045d6104a536600461504c565b610e4f565b3480156104b657600080fd5b506104ca6104c536600461509f565b610eae565b6040516103729190615481565b3480156104e357600080fd5b506104306104f236600461509f565b610ef9565b34801561050357600080fd5b5061051761051236600461509f565b610f2d565b60405161037291906154a2565b34801561053057600080fd5b50610365610f8f565b34801561054557600080fd5b5061034e610554366004615144565b610f95565b34801561056557600080fd5b50610579610574366004614fc7565b611192565b604051610372919061531c565b34801561059257600080fd5b5061034e6105a13660046150fc565b6111a7565b3480156105b257600080fd5b506105bb611270565b604051610372959493929190615568565b3480156105d857600080fd5b50610430611299565b3480156105ed57600080fd5b506103656112b1565b34801561060257600080fd5b506103656106113660046151f7565b6112b7565b34801561062257600080fd5b5061034e610631366004614fc7565b6113f0565b34801561064257600080fd5b506103656114a5565b34801561065757600080fd5b506106606114ab565b60405161037291906155ac565b34801561067957600080fd5b5061034e610688366004614fc7565b6114b7565b34801561069957600080fd5b50610430611579565b3480156106ae57600080fd5b5061034e6106bd366004615022565b611595565b3480156106ce57600080fd5b5061034e6106dd366004615199565b6115a7565b3480156106ee57600080fd5b50610365611621565b61034e610705366004614fe2565b611627565b34801561071657600080fd5b50610365611877565b34801561072b57600080fd5b5061034e61073a36600461509f565b61187d565b34801561074b57600080fd5b50610365611992565b34801561076057600080fd5b50610365611998565b34801561077557600080fd5b5061034e61078436600461509f565b6119b6565b34801561079557600080fd5b5061034e6107a436600461509f565b6119f6565b3480156107b557600080fd5b506105796107c4366004614fc7565b611a00565b3480156107d557600080fd5b506103656107e436600461509f565b611a15565b3480156107f557600080fd5b5061036561080436600461509f565b611aa0565b34801561081557600080fd5b5061081e611ab2565b60405161037291906152c3565b34801561083757600080fd5b50610660611b21565b34801561084c57600080fd5b5061034e611b2d565b34801561086157600080fd5b5061045d610870366004615128565b611b47565b34801561088157600080fd5b50610660611c97565b34801561089657600080fd5b506103656108a53660046150b7565b611cab565b3480156108b657600080fd5b50610430611d48565b3480156108cb57600080fd5b506103656108da366004614fc7565b611d64565b3480156108eb57600080fd5b5061045d6108fa366004615022565b611d76565b34801561090b57600080fd5b5061034e61091a366004614fc7565b611db7565b34801561092b57600080fd5b5061034e61093a36600461509f565b611e5a565b610947612087565b73ffffffffffffffffffffffffffffffffffffffff811660009081526010602052604090205460ff16610987576109876109826001836120aa565b61214c565b73ffffffffffffffffffffffffffffffffffffffff81166000908152601060205260409081902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00169055517ff50d0d312d501878616eb5e78ebf3ed6dcd3955aaef8165af9c6b057cc4832fb90610a02908390615224565b60405180910390a150565b600c5460009081610a2582600163ffffffff61215416565b6000818152601660205260409020600101549091508015610a4d57610a4d6109828383612173565b610a55612190565b610a5d612203565b600084815260166020526040902055610a74614eaf565b50600083815260166020908152604091829020825160a08101845281548082526001830154938201849052600283015482860181905260038401546060840181905260049094015460808401529451919488947fbb4a26fa0ace13ee4da343896c20eaa44a618fb9071fdd8c2e2c960a4583189d94610af6949193929161552a565b60405180910390a2610b066122a7565b6020810151610b4d57805160405185917fb463d19ecf455be65365092cf8e1db6934a0334cf8cd532ddf9964d01f36b5b291610b4491600091615372565b60405180910390a25b6020015193505050505b90565b6000610b64611299565b73ffffffffffffffffffffffffffffffffffffffff166370a08231836040518263ffffffff1660e01b8152600401610b9c9190615224565b60206040518083038186803b158015610bb457600080fd5b505afa158015610bc8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610bec9190810190615181565b90505b919050565b601560209081526000928352604080842090915290825290208054600182015460029092015490919083565b33610c29614ede565b73ffffffffffffffffffffffffffffffffffffffff821660009081527f05b8ccbb9d4d8fb16ea74ce3c29a41f1b461fbdaff4714a0d9a8eb05499746bc60205260409020610c76906122ea565b90506000610ca882602001516bffffffffffffffffffffffff1683604001516bffffffffffffffffffffffff16612390565b905080841115610cbf57610cbf61098285836123a6565b73ffffffffffffffffffffffffffffffffffffffff831660009081527f05b8ccbb9d4d8fb16ea74ce3c29a41f1b461fbdaff4714a0d9a8eb05499746bc60205260409020610d0d90856123c3565b610d15611299565b73ffffffffffffffffffffffffffffffffffffffff16639470b0bd84866040518363ffffffff1660e01b8152600401610d4f92919061529d565b600060405180830381600087803b158015610d6957600080fd5b505af1158015610d7d573d6000803e3d6000fd5b505050508273ffffffffffffffffffffffffffffffffffffffff167f85082129d87b2fe11527cb1b3b7a520aeb5aa6913f88a3d8757fe40d1db02fdd85604051610dc79190615327565b60405180910390a250505050565b601660205260009081526040902080546001820154600283015460038401546004909401549293919290919085565b73c02aaa39b223fe8d0a0e5c4f27ead9083c756cc290565b610e24614ede565b6000828152600760205260409020610bec906122ea565b610e4361244a565b610e4c81612491565b50565b610e57614ede565b610ea560056000846001811115610e6a57fe5b60ff1681526020808201929092526040908101600090812073ffffffffffffffffffffffffffffffffffffffff8816825290925290206122ea565b90505b92915050565b610eb6614efe565b506000908152601560209081526040808320600c548452825291829020825160608101845281548152600182015492810192909252600201549181019190915290565b60028181548110610f0657fe5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff16905081565b610f35614f1f565b506000908152600a602090815260409182902082518084019093525473ffffffffffffffffffffffffffffffffffffffff8116835274010000000000000000000000000000000000000000900463ffffffff169082015290565b600d5481565b3381610fa1575061118d565b6000610fb06020860186615128565b6001811115610fbb57fe5b148015610fdf57506000610fd26020850185615128565b6001811115610fdd57fe5b145b15610fea575061118d565b6001610ff96020860186615128565b600181111561100457fe5b141561101957611019846020013582846125c2565b60016110286020850185615128565b600181111561103357fe5b1415611048576110488360200135828461265b565b600060058161105a6020880188615128565b600181111561106557fe5b60ff1681526020808201929092526040908101600090812073ffffffffffffffffffffffffffffffffffffffff86168252835290812092509060059082906110af90880188615128565b60018111156110ba57fe5b60ff1681526020808201929092526040908101600090812073ffffffffffffffffffffffffffffffffffffffff87168252909252902090506110fd8282866126f4565b60208086013590870180359073ffffffffffffffffffffffffffffffffffffffff8616907f7d3ad1dcf03b9027064d1d9a474a69e0cecc31324c541d3eb9b5e6fa2f106c8d90889061114f908c615128565b600181111561115a57fe5b61116760208c018c615128565b600181111561117257fe5b60405161118193929190615593565b60405180910390a45050505b505050565b60106020526000908152604090205460ff1681565b816111b1816127ed565b6000838152600a602052604090205474010000000000000000000000000000000000000000900463ffffffff166111e9848285612826565b6000848152600a60205260409081902080547fffffffffffffffff00000000ffffffffffffffffffffffffffffffffffffffff167401000000000000000000000000000000000000000063ffffffff8716021790555184907f8ea2a7a959bd25f226b7b0a4393613f7fdcaa8404e8bad96aa52dc1c1459016790610dc790849087906155bd565b601154601254601354601454929363ffffffff9283169391928281169264010000000090041690565b73ba7f8b5fb1b19c1211c5d49550fcd149177a5eaf90565b60115481565b60085460009033906112d090600163ffffffff61286e16565b600881905591506112e582620f424086612826565b6112ed614f1f565b5060408051808201825273ffffffffffffffffffffffffffffffffffffffff838116825263ffffffff87811660208085019182526000888152600a9091528590208451815492517fffffffffffffffffffffffff00000000000000000000000000000000000000009093169416939093177fffffffffffffffff00000000ffffffffffffffffffffffffffffffffffffffff1674010000000000000000000000000000000000000000919092160217905590517fcec6fc86ea644053f6edff1160dfe3fa5c61e7a5ef9f873f145bb03a0bd319e7906113d190859085908990615330565b60405180910390a183156113e8576113e8836119b6565b505092915050565b6113f861244a565b73ffffffffffffffffffffffffffffffffffffffff811660009081526001602052604090205460ff16611431576114316109828261288a565b60005b6002548110156114a1578173ffffffffffffffffffffffffffffffffffffffff166002828154811061146257fe5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff161415611499576114948282612929565b6114a1565b600101611434565b5050565b600c5481565b60145463ffffffff1681565b6114bf612087565b73ffffffffffffffffffffffffffffffffffffffff811660009081526010602052604090205460ff16156114fb576114fb6109826000836120aa565b73ffffffffffffffffffffffffffffffffffffffff81166000908152601060205260409081902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00166001179055517f3e535d1ab441ef41c268fd9b52b478aee02d693c5ca2a84b5d26b89e0922e5e190610a02908390615224565b60005473ffffffffffffffffffffffffffffffffffffffff1681565b61159d61244a565b6114a18282612929565b6115af612087565b6115bc8585858585612b78565b3073ffffffffffffffffffffffffffffffffffffffff1663c6f3a4276040518163ffffffff1660e01b815260040160006040518083038186803b15801561160257600080fd5b505afa158015611616573d6000803e3d6000fd5b505050505050505050565b60135481565b3360009081526010602052604090205460ff1661164a5761164a61098233612c3b565b61165381612c56565b3461172d57611660610e04565b73ffffffffffffffffffffffffffffffffffffffff166323b872dd8330846040518463ffffffff1660e01b815260040161169c9392919061526c565b602060405180830381600087803b1580156116b657600080fd5b505af11580156116ca573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506116ee9190810190615083565b61172d576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016117249061544a565b60405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff83166000908152600960205260409020548061175e575061118d565b600061176982610e1c565b602001516bffffffffffffffffffffffff16905060135481101561178e57505061118d565b600c5460008381526015602090815260408083208484528252808320601690925290912081548061183d576000806117c68888612c77565b6002870182905560018701819055600386015491935091506117ee908263ffffffff61286e16565b60038501556001808501546118089163ffffffff61286e16565b6001850155604051889087907f14b098103235344975b17508c2391721cc9ac3f3fa2b56c7ff46f8480dfd074f90600090a350505b61184d818863ffffffff61286e16565b83556002820154611864908863ffffffff61286e16565b8260020181905550505050505050505050565b60085481565b33611886611299565b73ffffffffffffffffffffffffffffffffffffffff166315cc36f282846040518363ffffffff1660e01b81526004016118c092919061529d565b600060405180830381600087803b1580156118da57600080fd5b505af11580156118ee573d6000803e3d6000fd5b5050505073ffffffffffffffffffffffffffffffffffffffff811660009081527f05b8ccbb9d4d8fb16ea74ce3c29a41f1b461fbdaff4714a0d9a8eb05499746bc602052604090206119409083612d03565b8073ffffffffffffffffffffffffffffffffffffffff167febedb8b3c678666e7f36970bc8f57abf6d8fa2e828c0da91ea5b75bf68ed101a836040516119869190615327565b60405180910390a25050565b60175481565b60006119b1601154600d5461286e90919063ffffffff16565b905090565b3360008181526009602052604080822084905551839183917f5640833634fce74eb9211d1209a91dd5a1c8c6a751696bff9323b4db67f815139190a35050565b610e4c8133612d6d565b60016020526000908152604090205460ff1681565b6000611a1f614f1f565b506000828152600a6020908152604080832081518083019092525473ffffffffffffffffffffffffffffffffffffffff8116825274010000000000000000000000000000000000000000900463ffffffff16918101919091529080611a8385612f45565b91509150611a9683602001518383613002565b5095945050505050565b600b6020526000908152604090205481565b60606002805480602002602001604051908101604052809291908181526020018280548015611b1757602002820191906000526020600020905b815473ffffffffffffffffffffffffffffffffffffffff168152600190910190602001808311611aec575b5050505050905090565b60125463ffffffff1681565b611b35612087565b611b3d613043565b611b45613056565b565b611b4f614ede565b60016000526004602052611b827fabd6e7cb50984ff9c2f3e18a2660c3353dadf4e3291deeb275dae2cd1e44fe056122ea565b90506000826001811115611b9257fe5b1415610bef576000611ba2611299565b73ffffffffffffffffffffffffffffffffffffffff16639706e0c06040518163ffffffff1660e01b815260040160206040518083038186803b158015611be757600080fd5b505afa158015611bfb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250611c1f9190810190615181565b9050611c4e611c4983602001516bffffffffffffffffffffffff168361215490919063ffffffff16565b613081565b6bffffffffffffffffffffffff90811660208401526040830151611c7e91611c499184911663ffffffff61215416565b6bffffffffffffffffffffffff16604083015250919050565b601454640100000000900463ffffffff1681565b6000611cb5614f1f565b506000838152600a6020908152604080832081518083019092525473ffffffffffffffffffffffffffffffffffffffff8116825274010000000000000000000000000000000000000000900463ffffffff16918101919091529080611d1986612f45565b915091506000611d2e84602001518484613002565b915050611d3d878783856130a5565b979650505050505050565b60035473ffffffffffffffffffffffffffffffffffffffff1681565b60096020526000908152604090205481565b611d7e614ede565b73ffffffffffffffffffffffffffffffffffffffff831660009081526006602090815260408083208584529091529020610ea5906122ea565b611dbf61244a565b73ffffffffffffffffffffffffffffffffffffffff8116611dea57611de56109826131f2565b610e4c565b600080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff83169081178255604051909133917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a350565b600c546000611e7082600163ffffffff61215416565b9050611e7a614eaf565b50600081815260166020908152604091829020825160a08101845281548152600182015492810183905260028201549381019390935260038101546060840152600401546080830152611ecf57505050610e4c565b611ed7614efe565b5060008481526015602090815260408083208584528252918290208251606081018452815480825260018301549382019390935260029091015492810192909252611f255750505050610e4c565b6000858152601560209081526040808320868452909152812081815560018101829055600201819055611f588284613229565b9050600080611f6c8884866040015161329e565b9150915087877ff1116b309178aa62dcb6bf8c3b8bc2321724907c7ebf52192d14c8ce3aa9194c8484604051611fa3929190615372565b60405180910390a36000611fbd838363ffffffff61286e16565b6080870151909150611fd5908263ffffffff61286e16565b6080870181905260008881526016602090815260409091206004019190915586015161200890600163ffffffff61215416565b602080880182815260008a8152601690925260409091206001019190915551611616576080860151865188917fb463d19ecf455be65365092cf8e1db6934a0334cf8cd532ddf9964d01f36b5b291612066908263ffffffff61215416565b604051612074929190615372565b60405180910390a2505050505050505050565b3360009081526001602052604090205460ff16611b4557611b45610982336133ee565b606063b9588e4360e01b83836040516024016120c79291906153ba565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff0000000000000000000000000000000000000000000000000000000090931692909217909152905092915050565b805160208201fd5b60008282111561216d5761216d61098260028585613409565b50900390565b606063614b800a60e01b83836040516024016120c7929190615372565b30318015610e4c576121a0610e04565b73ffffffffffffffffffffffffffffffffffffffff1663d0e30db0826040518263ffffffff1660e01b81526004016000604051808303818588803b1580156121e757600080fd5b505af11580156121fb573d6000803e3d6000fd5b505050505050565b60006119b1601754612213610e04565b73ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b815260040161224b9190615224565b60206040518083038186803b15801561226357600080fd5b505afa158015612277573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061229b9190810190615181565b9063ffffffff61215416565b4260006122b2611998565b9050818111156122c9576122c961098282846134ae565b600c546000906122e090600163ffffffff61286e16565b600c555050600d55565b6122f2614ede565b5060408051606081018252825467ffffffffffffffff81168083526bffffffffffffffffffffffff680100000000000000008304811660208501527401000000000000000000000000000000000000000090920490911692820192909252600c54909181111561238a57612365816134cb565b67ffffffffffffffff16825260408201516bffffffffffffffffffffffff1660208301525b50919050565b600081831061239f5781610ea5565b5090919050565b60606384c8b7c960e01b83836040516024016120c7929190615372565b6123cb614ede565b6123d4836122ea565b90506123fe611c498383604001516bffffffffffffffffffffffff1661215490919063ffffffff16565b6bffffffffffffffffffffffff9081166040830152602082015161242d91611c4991168463ffffffff61215416565b6bffffffffffffffffffffffff16602082015261118d83826134eb565b60005473ffffffffffffffffffffffffffffffffffffffff163314611b4557600054611b459061098290339073ffffffffffffffffffffffffffffffffffffffff166135a5565b73ffffffffffffffffffffffffffffffffffffffff81166124b7576124b76109826135c2565b73ffffffffffffffffffffffffffffffffffffffff811660009081526001602052604090205460ff16156124f1576124f1610982826135f9565b73ffffffffffffffffffffffffffffffffffffffff8116600081815260016020819052604080832080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00168317905560028054928301815583527f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace90910180547fffffffffffffffffffffffff00000000000000000000000000000000000000001684179055513392917f3147867c59d17e8fa9d522465651d44aae0a9e38f902f3475b97e58072f0ed4c91a350565b6125cb83613614565b6125d58383612d6d565b73ffffffffffffffffffffffffffffffffffffffff82166000908152600660209081526040808320868452909152902061260f908261364b565b6000838152600760205260409020612627908261364b565b6001600052600460205261118d7fabd6e7cb50984ff9c2f3e18a2660c3353dadf4e3291deeb275dae2cd1e44fe058261364b565b61266483613614565b61266e8383612d6d565b73ffffffffffffffffffffffffffffffffffffffff8216600090815260066020908152604080832086845290915290206126a890826136a3565b60008381526007602052604090206126c090826136a3565b6001600052600460205261118d7fabd6e7cb50984ff9c2f3e18a2660c3353dadf4e3291deeb275dae2cd1e44fe05826136a3565b6126fe83836136de565b156127085761118d565b612710614ede565b612719846122ea565b9050612723614ede565b61272c846122ea565b905081604001516bffffffffffffffffffffffff16831115612767576127676109828484604001516bffffffffffffffffffffffff166123a6565b604082015161278e90611c49906bffffffffffffffffffffffff168563ffffffff61215416565b6bffffffffffffffffffffffff9081166040808501919091528201516127bf91611c4991168563ffffffff61286e16565b6bffffffffffffffffffffffff1660408201526127dc85836134eb565b6127e684826134eb565b5050505050565b6000818152600a602052604090205473ffffffffffffffffffffffffffffffffffffffff163381146114a1576114a161098233846136e5565b620f424063ffffffff8216111561284b5761284661098260008584613702565b61118d565b8163ffffffff168163ffffffff16111561118d5761118d61098260018584613702565b600082820183811015610ea557610ea561098260008686613409565b606063eb5108a260e01b826040516024016128a59190615224565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff00000000000000000000000000000000000000000000000000000000909316929092179091529050919050565b73ffffffffffffffffffffffffffffffffffffffff821660009081526001602052604090205460ff16612962576129626109828361288a565b600254811061297d5761297d61098282600280549050613721565b8173ffffffffffffffffffffffffffffffffffffffff16600282815481106129a157fe5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff1614612a0357612a03610982600283815481106129db57fe5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff168461373e565b73ffffffffffffffffffffffffffffffffffffffff8216600090815260016020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00169055600280547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8101908110612a7e57fe5b6000918252602090912001546002805473ffffffffffffffffffffffffffffffffffffffff9092169183908110612ab157fe5b600091825260209091200180547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055600280547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0190612b309082614f36565b50604051339073ffffffffffffffffffffffffffffffffffffffff8416907f1f32c1b084e2de0713b8fb16bd46bb9df710a3dbeae2f3ca93af46e016dcc6b090600090a35050565b60118590556012805463ffffffff8087167fffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000092831617909255601385905560148054848416640100000000027fffffffffffffffffffffffffffffffffffffffffffffffff00000000ffffffff9487169190931617929092161790556040517f613157dbb0e920deab8ad6ddd3805e87cbf57344b9fe780f1764790ec789754290612c2c9087908790879087908790615568565b60405180910390a15050505050565b606063b56d2df060e01b826040516024016128a59190615224565b803414158015612c6557503415155b15610e4c57610e4c610982823461375b565b6000828152600a602052604081205481908190612caa9073ffffffffffffffffffffffffffffffffffffffff1686611d76565b602001516bffffffffffffffffffffffff169050612cce848263ffffffff61215416565b601254909350612cf990612cec9063ffffffff16620f424086613778565b829063ffffffff61286e16565b9150509250929050565b612d0b614ede565b612d14836122ea565b9050612d3e611c498383604001516bffffffffffffffffffffffff1661286e90919063ffffffff16565b6bffffffffffffffffffffffff9081166040830152602082015161242d91611c4991168463ffffffff61286e16565b612d768261379a565b6000612d8583836000806130a5565b73ffffffffffffffffffffffffffffffffffffffff831660009081526006602090815260408083208784529091529020909150612dc1906122ea565b73ffffffffffffffffffffffffffffffffffffffff8381166000908152600660209081526040808320888452825291829020845181549286015195909301517fffffffffffffffffffffffffffffffffffffffffffffffff000000000000000090921667ffffffffffffffff909316929092177fffffffffffffffffffffffff000000000000000000000000ffffffffffffffff16680100000000000000006bffffffffffffffffffffffff95861602179092167401000000000000000000000000000000000000000093909216929092021790558015612f3c57612ea6838261380e565b612eae610e04565b73ffffffffffffffffffffffffffffffffffffffff1663a9059cbb83836040518363ffffffff1660e01b8152600401612ee892919061529d565b602060405180830381600087803b158015612f0257600080fd5b505af1158015612f16573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250612f3a9190810190615083565b505b61118d83613856565b6000806000612f606001600c5461215490919063ffffffff16565b9050612f6a614efe565b50600084815260156020908152604080832084845282528083208151606080820184528254825260018084015483870152600293840154838601528787526016865295849020845160a0810186528154815296810154958701959095529184015492850192909252600383015490840152600490910154608083015290612ff2908290613229565b9350806040015192505050915091565b600080826130125783915061303b565b61302663ffffffff8616620f424086613863565b9150613038848363ffffffff61215416565b90505b935093915050565b61304b613899565b42600d556001600c55565b61305e6138ae565b620d2f00620dbba068056bc75e2d63100000600260036127e68585858585612b78565b806bffffffffffffffffffffffff81168114610bef57610bef610982600284613913565b600c546000906130b3614ede565b5073ffffffffffffffffffffffffffffffffffffffff851660009081526006602090815260408083208984528252918290208251606081018452905467ffffffffffffffff81168083526bffffffffffffffffffffffff6801000000000000000083048116948401949094527401000000000000000000000000000000000000000090910490921692810192909252821415613154576000925050506131ea565b61316081838787613930565b81519093506000906131839067ffffffffffffffff16600163ffffffff61286e16565b90506131c16131b48984602001516bffffffffffffffffffffffff16856000015167ffffffffffffffff16856139b3565b859063ffffffff61286e16565b93506131e46131b48984604001516bffffffffffffffffffffffff1684876139b3565b93505050505b949350505050565b60408051808201909152600481527fe69edc3e00000000000000000000000000000000000000000000000000000000602082015290565b815160009061323757610ea8565b8151835160408401516020860151606086015160145461326d95949392919063ffffffff80821691640100000000900416613a4c565b608083015183519192506000916132899163ffffffff61215416565b905081811015613297578091505b5092915050565b6000806132a9614f1f565b506000858152600a602090815260409182902082518084019093525473ffffffffffffffffffffffffffffffffffffffff8116835274010000000000000000000000000000000000000000900463ffffffff1690820181905261330d908686613002565b909350915082156133ca57613320610e04565b81516040517fa9059cbb00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff929092169163a9059cbb9161337691879060040161529d565b602060405180830381600087803b15801561339057600080fd5b505af11580156133a4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506133c89190810190615083565b505b81156133e5576133da8683613b0f565b6133e5868386613b50565b50935093915050565b606063b65a25b960e01b826040516024016128a59190615224565b606063e946c1bb60e01b84848460405160240161342893929190615380565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff000000000000000000000000000000000000000000000000000000009093169290921790915290509392505050565b606063a6bcde4760e01b83836040516024016120c7929190615372565b8067ffffffffffffffff81168114610bef57610bef610982600184613913565b8051825460408301516020909301516bffffffffffffffffffffffff90811668010000000000000000027fffffffffffffffffffffffff000000000000000000000000ffffffffffffffff91909416740100000000000000000000000000000000000000000273ffffffffffffffffffffffffffffffffffffffff67ffffffffffffffff9094167fffffffffffffffffffffffffffffffffffffffffffffffff000000000000000090931692909217929092161716179055565b6060631de45ad160e01b83836040516024016120c7929190615245565b60408051808201909152600481527f57654fe400000000000000000000000000000000000000000000000000000000602082015290565b606063de16f1a060e01b826040516024016128a59190615224565b6000818152600a602052604090205473ffffffffffffffffffffffffffffffffffffffff16610e4c57610e4c610982826000613c39565b613653614ede565b61365c836122ea565b9050613686611c498383604001516bffffffffffffffffffffffff1661215490919063ffffffff16565b6bffffffffffffffffffffffff16604082015261118d83826134eb565b6136ab614ede565b6136b4836122ea565b9050613686611c498383604001516bffffffffffffffffffffffff1661286e90919063ffffffff16565b1460011690565b60606382ded78560e01b83836040516024016120c792919061529d565b60606322df959760e01b848484604051602401613428939291906153ec565b606063e9f8377160e01b83836040516024016120c7929190615372565b606063140a84db60e01b83836040516024016120c7929190615245565b60606331d7a50560e01b83836040516024016120c7929190615372565b60006131ea8361378e868563ffffffff613c5616565b9063ffffffff613c8716565b600c546000906137b190600163ffffffff61215416565b90506137bb614efe565b50600082815260156020908152604080832084845282529182902082516060810184528154808252600183015493820193909352600290910154928101929092521561118d5761118d6109828484613cb1565b6000828152600b602052604090205461382d908263ffffffff61215416565b6000838152600b602052604090205560175461384f908263ffffffff61215416565b6017555050565b610e4c8160006001613b50565b60006131ea8361378e61387d82600163ffffffff61215416565b61388d888763ffffffff613c5616565b9063ffffffff61286e16565b600d5415611b4557611b456109826000613cce565b601154158015906138c6575060125463ffffffff1615155b80156138d3575060135415155b80156138e6575060145463ffffffff1615155b80156139015750601454640100000000900463ffffffff1615155b15611b4557611b456109826001613cce565b606063c996af7b60e01b83836040516024016120c79291906153a2565b600082158061393d575081155b1561394a575060006131ea565b600061395d85600163ffffffff61215416565b865167ffffffffffffffff16101561397957856040015161397f565b85602001515b6bffffffffffffffffffffffff1690508061399e5760009150506131ea565b6139a9848483613778565b9695505050505050565b60008315806139c157508183145b156139ce575060006131ea565b818310613a07576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161172490615413565b613a0f614f5a565b613a198685613d0d565b9050613a23614f5a565b613a2d8785613d0d565b9050611d3d81600001518260200151846000015185602001518a613e2b565b600080613a598888613eb7565b90506000613a678787613eb7565b9050811580613a74575080155b15613a85575060009150611d3d9050565b600081831315613a9e57613a998284613f09565b613aa8565b613aa88383613f09565b9050613ad1613acc613ab983613f28565b8863ffffffff168863ffffffff166145ca565b6145d9565b905081831315613aea57613ae58282613f09565b613af4565b613af48282614bc3565b9050613b00818c614bef565b9b9a5050505050505050505050565b6000828152600b6020526040902054613b2e908263ffffffff61286e16565b6000838152600b602052604090205560175461384f908263ffffffff61286e16565b6000838152600f6020526040902054600c5480821415613b7157505061118d565b613b79614f5a565b506000858152600e602090815260408083208584528252918290208251808401909352805483526001015490820152613bb0614f5a565b613bb982614c31565b15613bf257613bd2826000015183602001518888614c3a565b60208301819052818352613be69190614c9c565b60208301528152613bfd565b602081018590528581525b6000878152600e6020908152604080832086845282528083208451815593820151600190940193909355978152600f9097529095205550505050565b6060639ae94f0160e01b83836040516024016120c7929190615362565b600082613c6557506000610ea8565b82820282848281613c7257fe5b0414610ea557610ea561098260018686613409565b600081613c9d57613c9d61098260038585613409565b6000828481613ca857fe5b04949350505050565b6060635caa0b0560e01b83836040516024016120c7929190615372565b60607f0b02d77300000000000000000000000000000000000000000000000000000000826001811115613cfd57fe5b6040516024016128a591906155d4565b613d15614f5a565b506000828152600e602090815260408083208484528252918290208251808401909352805483526001015490820152613d4d81614c31565b15613d5757610ea8565b6000613d6a83600163ffffffff61215416565b6000858152600e60209081526040808320848452825291829020825180840190935280548352600101549082015292509050613da582614c31565b15613db05750610ea8565b6000848152600f602052604090205483811015613e0d576000858152600e6020908152604080832084845282529182902082518084019093528054835260010154908201529250613e0083614c31565b15613e0d5750610ea89050565b50506040805180820190915260008152600160208201529392505050565b600081613e3a57506000613eae565b83613e5a57613e538561378e848963ffffffff613c5616565b9050613eae565b6000613e7f613e6f868863ffffffff613c5616565b61229b898763ffffffff613c5616565b90506000613e93828663ffffffff613c8716565b9050613ea98761378e868463ffffffff613c5616565b925050505b95945050505050565b600080831215613ecf57613ecf610982600185614cc5565b6000821215613ee657613ee6610982600184614cc5565b610ea5613f03846f80000000000000000000000000000000614d06565b83614d4e565b6000610ea5613f03846f80000000000000000000000000000000614d06565b60006f80000000000000000000000000000000821315613f5057613f50610982600184614dcf565b60008213613f6657613f66610982600084614dcf565b6f80000000000000000000000000000000821415613f8657506000610bef565b640733048c5a8213613fb957507fffffffffffffffffffffffffffffffe010000000000000000000000000000000610bef565b60008060006a01c8464f761647600000008513614018577ffffffffffffffffffffffffffffffff000000000000000000000000000000000909301926a01c8464f761647600000006f8000000000000000000000000000000086020594505b6cf1aaddd7742e900000000000008513614076577ffffffffffffffffffffffffffffffff800000000000000000000000000000000909301926cf1aaddd7742e900000000000006f8000000000000000000000000000000086020594505b6e0afe10820813d7800000000000000085136140d8577ffffffffffffffffffffffffffffffffc00000000000000000000000000000000909301926e0afe10820813d780000000000000006f8000000000000000000000000000000086020594505b6f02582ab704279ec00000000000000000851361413c577ffffffffffffffffffffffffffffffffe00000000000000000000000000000000909301926f02582ab704279ec000000000000000006f8000000000000000000000000000000086020594505b6f1152aaa3bf81cc00000000000000000085136141a0577fffffffffffffffffffffffffffffffff00000000000000000000000000000000909301926f1152aaa3bf81cc0000000000000000006f8000000000000000000000000000000086020594505b6f2f16ac6c59de700000000000000000008513614204577fffffffffffffffffffffffffffffffff80000000000000000000000000000000909301926f2f16ac6c59de700000000000000000006f8000000000000000000000000000000086020594505b6f4da2cbf1be58280000000000000000008513614268577fffffffffffffffffffffffffffffffffc0000000000000000000000000000000909301926f4da2cbf1be58280000000000000000006f8000000000000000000000000000000086020594505b6f63afbe7ab2082c00000000000000000085136142cc577fffffffffffffffffffffffffffffffffe0000000000000000000000000000000909301926f63afbe7ab2082c0000000000000000006f8000000000000000000000000000000086020594505b6f70f5a893b608861e1f58934f97aea57d8513614330577ffffffffffffffffffffffffffffffffff0000000000000000000000000000000909301926f70f5a893b608861e1f58934f97aea57d6f8000000000000000000000000000000086020594505b7fffffffffffffffffffffffffffffffff80000000000000000000000000000000850192508291506f80000000000000000000000000000000828002059050700100000000000000000000000000000000838103830205840193506f80000000000000000000000000000000818302816143a657fe5b059150700200000000000000000000000000000000836faaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa038302816143d757fe5b05840193506f80000000000000000000000000000000818302816143f757fe5b059150700300000000000000000000000000000000836f999999999999999999999999999999990383028161442857fe5b05840193506f800000000000000000000000000000008183028161444857fe5b059150700400000000000000000000000000000000836f924924924924924924924924924924920383028161447957fe5b05840193506f800000000000000000000000000000008183028161449957fe5b059150700500000000000000000000000000000000836f8e38e38e38e38e38e38e38e38e38e38e038302816144ca57fe5b05840193506f80000000000000000000000000000000818302816144ea57fe5b059150700600000000000000000000000000000000836f8ba2e8ba2e8ba2e8ba2e8ba2e8ba2e8b0383028161451b57fe5b05840193506f800000000000000000000000000000008183028161453b57fe5b059150700700000000000000000000000000000000836f89d89d89d89d89d89d89d89d89d89d890383028161456c57fe5b05840193506f800000000000000000000000000000008183028161458c57fe5b059150700800000000000000000000000000000000836f88888888888888888888888888888888038302816145bd57fe5b0584019350505050919050565b60006131ea613f038585614d06565b60007fffffffffffffffffffffffffffffffe01000000000000000000000000000000082121561460b57506000610bef565b8161462757506f80000000000000000000000000000000610bef565b600082131561463e5761463e610982600184614dcf565b6f800000000000000000000000000000006f1000000000000000000000000000000083078080028290056710e1b3be415a0000810293909301929091818302059050806705a0913f6b1e000002830192506f80000000000000000000000000000000828202816146aa57fe5b05905080670168244fdac7800002830192506f80000000000000000000000000000000828202816146d757fe5b05905080664807432bc1800002830192506f800000000000000000000000000000008282028161470357fe5b05905080660c0135dca0400002830192506f800000000000000000000000000000008282028161472f57fe5b059050806601b707b1cdc00002830192506f800000000000000000000000000000008282028161475b57fe5b059050806536e0f639b80002830192506f800000000000000000000000000000008282028161478657fe5b05905080650618fee9f80002830192506f80000000000000000000000000000000828202816147b157fe5b05905080649c197dcc0002830192506f80000000000000000000000000000000828202816147db57fe5b05905080640e30dce40002830192506f800000000000000000000000000000008282028161480557fe5b0590508064012ebd130002830192506f800000000000000000000000000000008282028161482f57fe5b059050806317499f0002830192506f800000000000000000000000000000008282028161485857fe5b059050806301a9d48002830192506f800000000000000000000000000000008282028161488157fe5b05905080621c638002830192506f80000000000000000000000000000000828202816148a957fe5b059050806201c63802830192506f80000000000000000000000000000000828202816148d157fe5b05905080611ab802830192506f80000000000000000000000000000000828202816148f857fe5b0590508061017c02830192506f800000000000000000000000000000008282028161491f57fe5b05905080601402830192506f800000000000000000000000000000008282028161494557fe5b600095909503946721c3677c82b400009190059384010582016f80000000000000000000000000000000019290507010000000000000000000000000000000008416156149b4577243cbaf42a000812488fc5c220ad7b97bf6e99e6cf1aaddd7742e56d32fb9f9974484020592505b7008000000000000000000000000000000008416156149f6577105d27a9f51c31b7c2f8038212a05747799916e0afe10820813d65dfe6a33c07f738f84020592505b700400000000000000000000000000000000841615614a3857701b4c902e273a58678d6d3bfdb93db96d026f02582ab704279e8efd15e0265855c47a84020592505b700200000000000000000000000000000000841615614a7a577003b1cc971a9bb5b9867477440d6d1577506f1152aaa3bf81cb9fdb76eae12d02957184020592505b700100000000000000000000000000000000841615614abc5770015bf0a8b1457695355fb8ac404e7a79e36f2f16ac6c59de6f8d5d6f63c1482a7c8684020592505b6f80000000000000000000000000000000841615614afc576fd3094c70f034de4b96ff7d5b6f99fcd86f4da2cbf1be5827f9eb3ad1aa9866ebb384020592505b6f40000000000000000000000000000000841615614b3c576fa45af1e1f40c333b3de1db4dd55f29a76f63afbe7ab2082ba1a0ae5e4eb1b479dc84020592505b6f20000000000000000000000000000000841615614b7c576f910b022db7ae67ce76b441c27035c6a16f70f5a893b608861e1f58934f97aea57d84020592505b6f10000000000000000000000000000000841615614bbc576f88415abbe9a76bead8d00cf112e4d4a86f783eafef1c0a8f3978c7f81824d62ebf84020592505b5050919050565b60006f80000000000000000000000000000000614be08484614d06565b81614be757fe5b059392505050565b600080821215614c0757614c07610982600184614cc5565b6000614c138484614d06565b905060008113614c27576000915050610ea8565b607f1c9392505050565b60200151151590565b60008085614c4c575082905081614c93565b83614c5b575084905083614c93565b614c7e614c6e858763ffffffff613c5616565b61388d888663ffffffff613c5616565b9150614c90858463ffffffff613c5616565b90505b94509492505050565b600080614cba84846f80000000000000000000000000000000614dfe565b915091509250929050565b60607fbd79545f00000000000000000000000000000000000000000000000000000000836001811115614cf457fe5b836040516024016120c79291906155e2565b600082614d1557506000610ea8565b5081810281838281614d2357fe5b05141580614d3a575082828281614d3657fe5b0514155b15610ea857610ea861098260018585614e6c565b600081614d6457614d6461098260028585614e6c565b7f800000000000000000000000000000000000000000000000000000000000000083148015614db25750817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff145b15614dc657614dc661098260038585614e6c565b818381614be757fe5b60607fed2f26a100000000000000000000000000000000000000000000000000000000836001811115614cf457fe5b60008082851180614e0e57508284115b15614e6357600084861015614e235784614e25565b855b9050614e37818563ffffffff613c8716565b9050614e49868263ffffffff613c8716565b9250614e5b858263ffffffff613c8716565b91505061303b565b50929391925050565b60607f8c12dfe700000000000000000000000000000000000000000000000000000000846003811115614e9b57fe5b8484604051602401613428939291906155f5565b6040518060a0016040528060008152602001600081526020016000815260200160008152602001600081525090565b604080516060810182526000808252602082018190529181019190915290565b60405180606001604052806000815260200160008152602001600081525090565b604080518082019091526000808252602082015290565b81548183558181111561118d5760008381526020902061118d918101908301614f74565b604051806040016040528060008152602001600081525090565b610b5791905b80821115614f8e5760008155600101614f7a565b5090565b803573ffffffffffffffffffffffffffffffffffffffff81168114610ea857600080fd5b60006040828403121561238a578081fd5b600060208284031215614fd8578081fd5b610ea58383614f92565b600080600060608486031215614ff6578182fd5b83356150018161561a565b925060208401356150118161561a565b929592945050506040919091013590565b60008060408385031215615034578182fd5b61503e8484614f92565b946020939093013593505050565b6000806040838503121561505e578182fd5b6150688484614f92565b915060208301356150788161564a565b809150509250929050565b600060208284031215615094578081fd5b8151610ea58161563c565b6000602082840312156150b0578081fd5b5035919050565b600080604083850312156150c9578182fd5b8235915060208301356150788161561a565b600080604083850312156150ed578182fd5b50508035926020909101359150565b6000806040838503121561510e578182fd5b82359150602083013563ffffffff81168114615078578182fd5b600060208284031215615139578081fd5b8135610ea58161564a565b600080600060a08486031215615158578283fd5b6151628585614fb6565b92506151718560408601614fb6565b9150608084013590509250925092565b600060208284031215615192578081fd5b5051919050565b600080600080600060a086880312156151b0578283fd5b8535945060208601356151c281615657565b93506040860135925060608601356151d981615657565b915060808601356151e981615657565b809150509295509295909350565b60008060408385031215615209578182fd5b823561521481615657565b915060208301356150788161563c565b73ffffffffffffffffffffffffffffffffffffffff91909116815260200190565b73ffffffffffffffffffffffffffffffffffffffff92831681529116602082015260400190565b73ffffffffffffffffffffffffffffffffffffffff9384168152919092166020820152604081019190915260600190565b73ffffffffffffffffffffffffffffffffffffffff929092168252602082015260400190565b602080825282518282018190526000918401906040840190835b8181101561531157835173ffffffffffffffffffffffffffffffffffffffff168352602093840193909201916001016152dd565b509095945050505050565b901515815260200190565b90815260200190565b92835273ffffffffffffffffffffffffffffffffffffffff91909116602083015263ffffffff16604082015260600190565b9182521515602082015260400190565b918252602082015260400190565b606081016004851061538e57fe5b938152602081019290925260409091015290565b60408101600384106153b057fe5b9281526020015290565b604081016153c784615610565b92815273ffffffffffffffffffffffffffffffffffffffff9190911660209091015290565b606081016153f985615610565b938152602081019290925263ffffffff1660409091015290565b60208082526013908201527f43525f494e54455256414c5f494e56414c494400000000000000000000000000604082015260600190565b60208082526014908201527f574554485f5452414e534645525f4641494c4544000000000000000000000000604082015260600190565b81518152602080830151908201526040918201519181019190915260600190565b815173ffffffffffffffffffffffffffffffffffffffff16815260209182015163ffffffff169181019190915260400190565b815167ffffffffffffffff1681526020808301516bffffffffffffffffffffffff90811691830191909152604092830151169181019190915260600190565b9283526020830191909152604082015260600190565b93845260208401929092526040830152606082015260800190565b948552602085019390935260408401919091526060830152608082015260a00190565b94855263ffffffff938416602086015260408501929092528216606084015216608082015260a00190565b92835260ff918216602084015216604082015260600190565b63ffffffff91909116815260200190565b63ffffffff92831681529116602082015260400190565b60ff91909116815260200190565b60ff929092168252602082015260400190565b60ff9390931683526020830191909152604082015260600190565b60028110610e4c57fe5b73ffffffffffffffffffffffffffffffffffffffff81168114610e4c57600080fd5b8015158114610e4c57600080fd5b60028110610e4c57600080fd5b63ffffffff81168114610e4c57600080fdfea365627a7a72315820006210cdecfe6b555e273506a51e8f70592803d6dba0c5040fa921b6f79ac2176c6578706572696d656e74616cf564736f6c634300050c0040

Deployed Bytecode

0x6080604052600436106103295760003560e01c80638da5cb5b116101a5578063bb7ef7e0116100ec578063e8eeb3f811610095578063f18765321161006f578063f1876532146108bf578063f252b7a1146108df578063f2fde38b146108ff578063ff691b111461091f57610329565b8063e8eeb3f814610875578063e907f0031461088a578063ee99205c146108aa57610329565b8063e0ee036e116100c6578063e0ee036e1461082b578063e1c7392a14610840578063e804d0a41461085557610329565b8063bb7ef7e0146107c9578063c18c9141146107e9578063d39de6e91461080957610329565b8063a694fc3a1161014e578063b3e3337911610128578063b3e3337914610769578063b510879f14610789578063b9181611146107a957610329565b8063a694fc3a1461071f578063b05315241461073f578063b2baa33e1461075457610329565b8063a26171e21161017f578063a26171e2146106e2578063a3b4a327146106f7578063a657e5791461070a57610329565b80638da5cb5b1461068d5780639ad26744146106a25780639c3ccc82146106c257610329565b80634bcc3f6711610274578063624a72321161021d57806370712939116101f757806370712939146106165780637667180814610636578063816667961461064b5780638a2e271a1461066d57610329565b8063624a7232146105cc57806363403801146105e157806368a7d6cd146105f657610329565b80635bd4ab731161024e5780635bd4ab73146105595780635d91121d146105865780635e615a6b146105a657610329565b80634bcc3f67146104f7578063587da0231461052457806358f6c7e31461053957610329565b80633c277fc5116102d657806344a6958b116102b057806344a6958b1461048a57806346b97959146104aa578063494503d4146104d757610329565b80633c277fc51461041b5780633e4ad7321461043d57806342f1181e1461046a57610329565b80632a94c279116103075780632a94c2791461039b5780632e17de78146103ca57806338229d93146103ea57610329565b806301e28d841461032e5780630b9663db146103505780631e7ff8f61461037b575b600080fd5b34801561033a57600080fd5b5061034e610349366004614fc7565b61093f565b005b34801561035c57600080fd5b50610365610a0d565b6040516103729190615327565b60405180910390f35b34801561038757600080fd5b50610365610396366004614fc7565b610b5a565b3480156103a757600080fd5b506103bb6103b63660046150db565b610bf4565b60405161037293929190615514565b3480156103d657600080fd5b5061034e6103e536600461509f565b610c20565b3480156103f657600080fd5b5061040a61040536600461509f565b610dd5565b604051610372959493929190615545565b34801561042757600080fd5b50610430610e04565b6040516103729190615224565b34801561044957600080fd5b5061045d61045836600461509f565b610e1c565b60405161037291906154d5565b34801561047657600080fd5b5061034e610485366004614fc7565b610e3b565b34801561049657600080fd5b5061045d6104a536600461504c565b610e4f565b3480156104b657600080fd5b506104ca6104c536600461509f565b610eae565b6040516103729190615481565b3480156104e357600080fd5b506104306104f236600461509f565b610ef9565b34801561050357600080fd5b5061051761051236600461509f565b610f2d565b60405161037291906154a2565b34801561053057600080fd5b50610365610f8f565b34801561054557600080fd5b5061034e610554366004615144565b610f95565b34801561056557600080fd5b50610579610574366004614fc7565b611192565b604051610372919061531c565b34801561059257600080fd5b5061034e6105a13660046150fc565b6111a7565b3480156105b257600080fd5b506105bb611270565b604051610372959493929190615568565b3480156105d857600080fd5b50610430611299565b3480156105ed57600080fd5b506103656112b1565b34801561060257600080fd5b506103656106113660046151f7565b6112b7565b34801561062257600080fd5b5061034e610631366004614fc7565b6113f0565b34801561064257600080fd5b506103656114a5565b34801561065757600080fd5b506106606114ab565b60405161037291906155ac565b34801561067957600080fd5b5061034e610688366004614fc7565b6114b7565b34801561069957600080fd5b50610430611579565b3480156106ae57600080fd5b5061034e6106bd366004615022565b611595565b3480156106ce57600080fd5b5061034e6106dd366004615199565b6115a7565b3480156106ee57600080fd5b50610365611621565b61034e610705366004614fe2565b611627565b34801561071657600080fd5b50610365611877565b34801561072b57600080fd5b5061034e61073a36600461509f565b61187d565b34801561074b57600080fd5b50610365611992565b34801561076057600080fd5b50610365611998565b34801561077557600080fd5b5061034e61078436600461509f565b6119b6565b34801561079557600080fd5b5061034e6107a436600461509f565b6119f6565b3480156107b557600080fd5b506105796107c4366004614fc7565b611a00565b3480156107d557600080fd5b506103656107e436600461509f565b611a15565b3480156107f557600080fd5b5061036561080436600461509f565b611aa0565b34801561081557600080fd5b5061081e611ab2565b60405161037291906152c3565b34801561083757600080fd5b50610660611b21565b34801561084c57600080fd5b5061034e611b2d565b34801561086157600080fd5b5061045d610870366004615128565b611b47565b34801561088157600080fd5b50610660611c97565b34801561089657600080fd5b506103656108a53660046150b7565b611cab565b3480156108b657600080fd5b50610430611d48565b3480156108cb57600080fd5b506103656108da366004614fc7565b611d64565b3480156108eb57600080fd5b5061045d6108fa366004615022565b611d76565b34801561090b57600080fd5b5061034e61091a366004614fc7565b611db7565b34801561092b57600080fd5b5061034e61093a36600461509f565b611e5a565b610947612087565b73ffffffffffffffffffffffffffffffffffffffff811660009081526010602052604090205460ff16610987576109876109826001836120aa565b61214c565b73ffffffffffffffffffffffffffffffffffffffff81166000908152601060205260409081902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00169055517ff50d0d312d501878616eb5e78ebf3ed6dcd3955aaef8165af9c6b057cc4832fb90610a02908390615224565b60405180910390a150565b600c5460009081610a2582600163ffffffff61215416565b6000818152601660205260409020600101549091508015610a4d57610a4d6109828383612173565b610a55612190565b610a5d612203565b600084815260166020526040902055610a74614eaf565b50600083815260166020908152604091829020825160a08101845281548082526001830154938201849052600283015482860181905260038401546060840181905260049094015460808401529451919488947fbb4a26fa0ace13ee4da343896c20eaa44a618fb9071fdd8c2e2c960a4583189d94610af6949193929161552a565b60405180910390a2610b066122a7565b6020810151610b4d57805160405185917fb463d19ecf455be65365092cf8e1db6934a0334cf8cd532ddf9964d01f36b5b291610b4491600091615372565b60405180910390a25b6020015193505050505b90565b6000610b64611299565b73ffffffffffffffffffffffffffffffffffffffff166370a08231836040518263ffffffff1660e01b8152600401610b9c9190615224565b60206040518083038186803b158015610bb457600080fd5b505afa158015610bc8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610bec9190810190615181565b90505b919050565b601560209081526000928352604080842090915290825290208054600182015460029092015490919083565b33610c29614ede565b73ffffffffffffffffffffffffffffffffffffffff821660009081527f05b8ccbb9d4d8fb16ea74ce3c29a41f1b461fbdaff4714a0d9a8eb05499746bc60205260409020610c76906122ea565b90506000610ca882602001516bffffffffffffffffffffffff1683604001516bffffffffffffffffffffffff16612390565b905080841115610cbf57610cbf61098285836123a6565b73ffffffffffffffffffffffffffffffffffffffff831660009081527f05b8ccbb9d4d8fb16ea74ce3c29a41f1b461fbdaff4714a0d9a8eb05499746bc60205260409020610d0d90856123c3565b610d15611299565b73ffffffffffffffffffffffffffffffffffffffff16639470b0bd84866040518363ffffffff1660e01b8152600401610d4f92919061529d565b600060405180830381600087803b158015610d6957600080fd5b505af1158015610d7d573d6000803e3d6000fd5b505050508273ffffffffffffffffffffffffffffffffffffffff167f85082129d87b2fe11527cb1b3b7a520aeb5aa6913f88a3d8757fe40d1db02fdd85604051610dc79190615327565b60405180910390a250505050565b601660205260009081526040902080546001820154600283015460038401546004909401549293919290919085565b73c02aaa39b223fe8d0a0e5c4f27ead9083c756cc290565b610e24614ede565b6000828152600760205260409020610bec906122ea565b610e4361244a565b610e4c81612491565b50565b610e57614ede565b610ea560056000846001811115610e6a57fe5b60ff1681526020808201929092526040908101600090812073ffffffffffffffffffffffffffffffffffffffff8816825290925290206122ea565b90505b92915050565b610eb6614efe565b506000908152601560209081526040808320600c548452825291829020825160608101845281548152600182015492810192909252600201549181019190915290565b60028181548110610f0657fe5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff16905081565b610f35614f1f565b506000908152600a602090815260409182902082518084019093525473ffffffffffffffffffffffffffffffffffffffff8116835274010000000000000000000000000000000000000000900463ffffffff169082015290565b600d5481565b3381610fa1575061118d565b6000610fb06020860186615128565b6001811115610fbb57fe5b148015610fdf57506000610fd26020850185615128565b6001811115610fdd57fe5b145b15610fea575061118d565b6001610ff96020860186615128565b600181111561100457fe5b141561101957611019846020013582846125c2565b60016110286020850185615128565b600181111561103357fe5b1415611048576110488360200135828461265b565b600060058161105a6020880188615128565b600181111561106557fe5b60ff1681526020808201929092526040908101600090812073ffffffffffffffffffffffffffffffffffffffff86168252835290812092509060059082906110af90880188615128565b60018111156110ba57fe5b60ff1681526020808201929092526040908101600090812073ffffffffffffffffffffffffffffffffffffffff87168252909252902090506110fd8282866126f4565b60208086013590870180359073ffffffffffffffffffffffffffffffffffffffff8616907f7d3ad1dcf03b9027064d1d9a474a69e0cecc31324c541d3eb9b5e6fa2f106c8d90889061114f908c615128565b600181111561115a57fe5b61116760208c018c615128565b600181111561117257fe5b60405161118193929190615593565b60405180910390a45050505b505050565b60106020526000908152604090205460ff1681565b816111b1816127ed565b6000838152600a602052604090205474010000000000000000000000000000000000000000900463ffffffff166111e9848285612826565b6000848152600a60205260409081902080547fffffffffffffffff00000000ffffffffffffffffffffffffffffffffffffffff167401000000000000000000000000000000000000000063ffffffff8716021790555184907f8ea2a7a959bd25f226b7b0a4393613f7fdcaa8404e8bad96aa52dc1c1459016790610dc790849087906155bd565b601154601254601354601454929363ffffffff9283169391928281169264010000000090041690565b73ba7f8b5fb1b19c1211c5d49550fcd149177a5eaf90565b60115481565b60085460009033906112d090600163ffffffff61286e16565b600881905591506112e582620f424086612826565b6112ed614f1f565b5060408051808201825273ffffffffffffffffffffffffffffffffffffffff838116825263ffffffff87811660208085019182526000888152600a9091528590208451815492517fffffffffffffffffffffffff00000000000000000000000000000000000000009093169416939093177fffffffffffffffff00000000ffffffffffffffffffffffffffffffffffffffff1674010000000000000000000000000000000000000000919092160217905590517fcec6fc86ea644053f6edff1160dfe3fa5c61e7a5ef9f873f145bb03a0bd319e7906113d190859085908990615330565b60405180910390a183156113e8576113e8836119b6565b505092915050565b6113f861244a565b73ffffffffffffffffffffffffffffffffffffffff811660009081526001602052604090205460ff16611431576114316109828261288a565b60005b6002548110156114a1578173ffffffffffffffffffffffffffffffffffffffff166002828154811061146257fe5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff161415611499576114948282612929565b6114a1565b600101611434565b5050565b600c5481565b60145463ffffffff1681565b6114bf612087565b73ffffffffffffffffffffffffffffffffffffffff811660009081526010602052604090205460ff16156114fb576114fb6109826000836120aa565b73ffffffffffffffffffffffffffffffffffffffff81166000908152601060205260409081902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00166001179055517f3e535d1ab441ef41c268fd9b52b478aee02d693c5ca2a84b5d26b89e0922e5e190610a02908390615224565b60005473ffffffffffffffffffffffffffffffffffffffff1681565b61159d61244a565b6114a18282612929565b6115af612087565b6115bc8585858585612b78565b3073ffffffffffffffffffffffffffffffffffffffff1663c6f3a4276040518163ffffffff1660e01b815260040160006040518083038186803b15801561160257600080fd5b505afa158015611616573d6000803e3d6000fd5b505050505050505050565b60135481565b3360009081526010602052604090205460ff1661164a5761164a61098233612c3b565b61165381612c56565b3461172d57611660610e04565b73ffffffffffffffffffffffffffffffffffffffff166323b872dd8330846040518463ffffffff1660e01b815260040161169c9392919061526c565b602060405180830381600087803b1580156116b657600080fd5b505af11580156116ca573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506116ee9190810190615083565b61172d576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016117249061544a565b60405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff83166000908152600960205260409020548061175e575061118d565b600061176982610e1c565b602001516bffffffffffffffffffffffff16905060135481101561178e57505061118d565b600c5460008381526015602090815260408083208484528252808320601690925290912081548061183d576000806117c68888612c77565b6002870182905560018701819055600386015491935091506117ee908263ffffffff61286e16565b60038501556001808501546118089163ffffffff61286e16565b6001850155604051889087907f14b098103235344975b17508c2391721cc9ac3f3fa2b56c7ff46f8480dfd074f90600090a350505b61184d818863ffffffff61286e16565b83556002820154611864908863ffffffff61286e16565b8260020181905550505050505050505050565b60085481565b33611886611299565b73ffffffffffffffffffffffffffffffffffffffff166315cc36f282846040518363ffffffff1660e01b81526004016118c092919061529d565b600060405180830381600087803b1580156118da57600080fd5b505af11580156118ee573d6000803e3d6000fd5b5050505073ffffffffffffffffffffffffffffffffffffffff811660009081527f05b8ccbb9d4d8fb16ea74ce3c29a41f1b461fbdaff4714a0d9a8eb05499746bc602052604090206119409083612d03565b8073ffffffffffffffffffffffffffffffffffffffff167febedb8b3c678666e7f36970bc8f57abf6d8fa2e828c0da91ea5b75bf68ed101a836040516119869190615327565b60405180910390a25050565b60175481565b60006119b1601154600d5461286e90919063ffffffff16565b905090565b3360008181526009602052604080822084905551839183917f5640833634fce74eb9211d1209a91dd5a1c8c6a751696bff9323b4db67f815139190a35050565b610e4c8133612d6d565b60016020526000908152604090205460ff1681565b6000611a1f614f1f565b506000828152600a6020908152604080832081518083019092525473ffffffffffffffffffffffffffffffffffffffff8116825274010000000000000000000000000000000000000000900463ffffffff16918101919091529080611a8385612f45565b91509150611a9683602001518383613002565b5095945050505050565b600b6020526000908152604090205481565b60606002805480602002602001604051908101604052809291908181526020018280548015611b1757602002820191906000526020600020905b815473ffffffffffffffffffffffffffffffffffffffff168152600190910190602001808311611aec575b5050505050905090565b60125463ffffffff1681565b611b35612087565b611b3d613043565b611b45613056565b565b611b4f614ede565b60016000526004602052611b827fabd6e7cb50984ff9c2f3e18a2660c3353dadf4e3291deeb275dae2cd1e44fe056122ea565b90506000826001811115611b9257fe5b1415610bef576000611ba2611299565b73ffffffffffffffffffffffffffffffffffffffff16639706e0c06040518163ffffffff1660e01b815260040160206040518083038186803b158015611be757600080fd5b505afa158015611bfb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250611c1f9190810190615181565b9050611c4e611c4983602001516bffffffffffffffffffffffff168361215490919063ffffffff16565b613081565b6bffffffffffffffffffffffff90811660208401526040830151611c7e91611c499184911663ffffffff61215416565b6bffffffffffffffffffffffff16604083015250919050565b601454640100000000900463ffffffff1681565b6000611cb5614f1f565b506000838152600a6020908152604080832081518083019092525473ffffffffffffffffffffffffffffffffffffffff8116825274010000000000000000000000000000000000000000900463ffffffff16918101919091529080611d1986612f45565b915091506000611d2e84602001518484613002565b915050611d3d878783856130a5565b979650505050505050565b60035473ffffffffffffffffffffffffffffffffffffffff1681565b60096020526000908152604090205481565b611d7e614ede565b73ffffffffffffffffffffffffffffffffffffffff831660009081526006602090815260408083208584529091529020610ea5906122ea565b611dbf61244a565b73ffffffffffffffffffffffffffffffffffffffff8116611dea57611de56109826131f2565b610e4c565b600080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff83169081178255604051909133917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a350565b600c546000611e7082600163ffffffff61215416565b9050611e7a614eaf565b50600081815260166020908152604091829020825160a08101845281548152600182015492810183905260028201549381019390935260038101546060840152600401546080830152611ecf57505050610e4c565b611ed7614efe565b5060008481526015602090815260408083208584528252918290208251606081018452815480825260018301549382019390935260029091015492810192909252611f255750505050610e4c565b6000858152601560209081526040808320868452909152812081815560018101829055600201819055611f588284613229565b9050600080611f6c8884866040015161329e565b9150915087877ff1116b309178aa62dcb6bf8c3b8bc2321724907c7ebf52192d14c8ce3aa9194c8484604051611fa3929190615372565b60405180910390a36000611fbd838363ffffffff61286e16565b6080870151909150611fd5908263ffffffff61286e16565b6080870181905260008881526016602090815260409091206004019190915586015161200890600163ffffffff61215416565b602080880182815260008a8152601690925260409091206001019190915551611616576080860151865188917fb463d19ecf455be65365092cf8e1db6934a0334cf8cd532ddf9964d01f36b5b291612066908263ffffffff61215416565b604051612074929190615372565b60405180910390a2505050505050505050565b3360009081526001602052604090205460ff16611b4557611b45610982336133ee565b606063b9588e4360e01b83836040516024016120c79291906153ba565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff0000000000000000000000000000000000000000000000000000000090931692909217909152905092915050565b805160208201fd5b60008282111561216d5761216d61098260028585613409565b50900390565b606063614b800a60e01b83836040516024016120c7929190615372565b30318015610e4c576121a0610e04565b73ffffffffffffffffffffffffffffffffffffffff1663d0e30db0826040518263ffffffff1660e01b81526004016000604051808303818588803b1580156121e757600080fd5b505af11580156121fb573d6000803e3d6000fd5b505050505050565b60006119b1601754612213610e04565b73ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b815260040161224b9190615224565b60206040518083038186803b15801561226357600080fd5b505afa158015612277573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061229b9190810190615181565b9063ffffffff61215416565b4260006122b2611998565b9050818111156122c9576122c961098282846134ae565b600c546000906122e090600163ffffffff61286e16565b600c555050600d55565b6122f2614ede565b5060408051606081018252825467ffffffffffffffff81168083526bffffffffffffffffffffffff680100000000000000008304811660208501527401000000000000000000000000000000000000000090920490911692820192909252600c54909181111561238a57612365816134cb565b67ffffffffffffffff16825260408201516bffffffffffffffffffffffff1660208301525b50919050565b600081831061239f5781610ea5565b5090919050565b60606384c8b7c960e01b83836040516024016120c7929190615372565b6123cb614ede565b6123d4836122ea565b90506123fe611c498383604001516bffffffffffffffffffffffff1661215490919063ffffffff16565b6bffffffffffffffffffffffff9081166040830152602082015161242d91611c4991168463ffffffff61215416565b6bffffffffffffffffffffffff16602082015261118d83826134eb565b60005473ffffffffffffffffffffffffffffffffffffffff163314611b4557600054611b459061098290339073ffffffffffffffffffffffffffffffffffffffff166135a5565b73ffffffffffffffffffffffffffffffffffffffff81166124b7576124b76109826135c2565b73ffffffffffffffffffffffffffffffffffffffff811660009081526001602052604090205460ff16156124f1576124f1610982826135f9565b73ffffffffffffffffffffffffffffffffffffffff8116600081815260016020819052604080832080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00168317905560028054928301815583527f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace90910180547fffffffffffffffffffffffff00000000000000000000000000000000000000001684179055513392917f3147867c59d17e8fa9d522465651d44aae0a9e38f902f3475b97e58072f0ed4c91a350565b6125cb83613614565b6125d58383612d6d565b73ffffffffffffffffffffffffffffffffffffffff82166000908152600660209081526040808320868452909152902061260f908261364b565b6000838152600760205260409020612627908261364b565b6001600052600460205261118d7fabd6e7cb50984ff9c2f3e18a2660c3353dadf4e3291deeb275dae2cd1e44fe058261364b565b61266483613614565b61266e8383612d6d565b73ffffffffffffffffffffffffffffffffffffffff8216600090815260066020908152604080832086845290915290206126a890826136a3565b60008381526007602052604090206126c090826136a3565b6001600052600460205261118d7fabd6e7cb50984ff9c2f3e18a2660c3353dadf4e3291deeb275dae2cd1e44fe05826136a3565b6126fe83836136de565b156127085761118d565b612710614ede565b612719846122ea565b9050612723614ede565b61272c846122ea565b905081604001516bffffffffffffffffffffffff16831115612767576127676109828484604001516bffffffffffffffffffffffff166123a6565b604082015161278e90611c49906bffffffffffffffffffffffff168563ffffffff61215416565b6bffffffffffffffffffffffff9081166040808501919091528201516127bf91611c4991168563ffffffff61286e16565b6bffffffffffffffffffffffff1660408201526127dc85836134eb565b6127e684826134eb565b5050505050565b6000818152600a602052604090205473ffffffffffffffffffffffffffffffffffffffff163381146114a1576114a161098233846136e5565b620f424063ffffffff8216111561284b5761284661098260008584613702565b61118d565b8163ffffffff168163ffffffff16111561118d5761118d61098260018584613702565b600082820183811015610ea557610ea561098260008686613409565b606063eb5108a260e01b826040516024016128a59190615224565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff00000000000000000000000000000000000000000000000000000000909316929092179091529050919050565b73ffffffffffffffffffffffffffffffffffffffff821660009081526001602052604090205460ff16612962576129626109828361288a565b600254811061297d5761297d61098282600280549050613721565b8173ffffffffffffffffffffffffffffffffffffffff16600282815481106129a157fe5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff1614612a0357612a03610982600283815481106129db57fe5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff168461373e565b73ffffffffffffffffffffffffffffffffffffffff8216600090815260016020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00169055600280547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8101908110612a7e57fe5b6000918252602090912001546002805473ffffffffffffffffffffffffffffffffffffffff9092169183908110612ab157fe5b600091825260209091200180547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055600280547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0190612b309082614f36565b50604051339073ffffffffffffffffffffffffffffffffffffffff8416907f1f32c1b084e2de0713b8fb16bd46bb9df710a3dbeae2f3ca93af46e016dcc6b090600090a35050565b60118590556012805463ffffffff8087167fffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000092831617909255601385905560148054848416640100000000027fffffffffffffffffffffffffffffffffffffffffffffffff00000000ffffffff9487169190931617929092161790556040517f613157dbb0e920deab8ad6ddd3805e87cbf57344b9fe780f1764790ec789754290612c2c9087908790879087908790615568565b60405180910390a15050505050565b606063b56d2df060e01b826040516024016128a59190615224565b803414158015612c6557503415155b15610e4c57610e4c610982823461375b565b6000828152600a602052604081205481908190612caa9073ffffffffffffffffffffffffffffffffffffffff1686611d76565b602001516bffffffffffffffffffffffff169050612cce848263ffffffff61215416565b601254909350612cf990612cec9063ffffffff16620f424086613778565b829063ffffffff61286e16565b9150509250929050565b612d0b614ede565b612d14836122ea565b9050612d3e611c498383604001516bffffffffffffffffffffffff1661286e90919063ffffffff16565b6bffffffffffffffffffffffff9081166040830152602082015161242d91611c4991168463ffffffff61286e16565b612d768261379a565b6000612d8583836000806130a5565b73ffffffffffffffffffffffffffffffffffffffff831660009081526006602090815260408083208784529091529020909150612dc1906122ea565b73ffffffffffffffffffffffffffffffffffffffff8381166000908152600660209081526040808320888452825291829020845181549286015195909301517fffffffffffffffffffffffffffffffffffffffffffffffff000000000000000090921667ffffffffffffffff909316929092177fffffffffffffffffffffffff000000000000000000000000ffffffffffffffff16680100000000000000006bffffffffffffffffffffffff95861602179092167401000000000000000000000000000000000000000093909216929092021790558015612f3c57612ea6838261380e565b612eae610e04565b73ffffffffffffffffffffffffffffffffffffffff1663a9059cbb83836040518363ffffffff1660e01b8152600401612ee892919061529d565b602060405180830381600087803b158015612f0257600080fd5b505af1158015612f16573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250612f3a9190810190615083565b505b61118d83613856565b6000806000612f606001600c5461215490919063ffffffff16565b9050612f6a614efe565b50600084815260156020908152604080832084845282528083208151606080820184528254825260018084015483870152600293840154838601528787526016865295849020845160a0810186528154815296810154958701959095529184015492850192909252600383015490840152600490910154608083015290612ff2908290613229565b9350806040015192505050915091565b600080826130125783915061303b565b61302663ffffffff8616620f424086613863565b9150613038848363ffffffff61215416565b90505b935093915050565b61304b613899565b42600d556001600c55565b61305e6138ae565b620d2f00620dbba068056bc75e2d63100000600260036127e68585858585612b78565b806bffffffffffffffffffffffff81168114610bef57610bef610982600284613913565b600c546000906130b3614ede565b5073ffffffffffffffffffffffffffffffffffffffff851660009081526006602090815260408083208984528252918290208251606081018452905467ffffffffffffffff81168083526bffffffffffffffffffffffff6801000000000000000083048116948401949094527401000000000000000000000000000000000000000090910490921692810192909252821415613154576000925050506131ea565b61316081838787613930565b81519093506000906131839067ffffffffffffffff16600163ffffffff61286e16565b90506131c16131b48984602001516bffffffffffffffffffffffff16856000015167ffffffffffffffff16856139b3565b859063ffffffff61286e16565b93506131e46131b48984604001516bffffffffffffffffffffffff1684876139b3565b93505050505b949350505050565b60408051808201909152600481527fe69edc3e00000000000000000000000000000000000000000000000000000000602082015290565b815160009061323757610ea8565b8151835160408401516020860151606086015160145461326d95949392919063ffffffff80821691640100000000900416613a4c565b608083015183519192506000916132899163ffffffff61215416565b905081811015613297578091505b5092915050565b6000806132a9614f1f565b506000858152600a602090815260409182902082518084019093525473ffffffffffffffffffffffffffffffffffffffff8116835274010000000000000000000000000000000000000000900463ffffffff1690820181905261330d908686613002565b909350915082156133ca57613320610e04565b81516040517fa9059cbb00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff929092169163a9059cbb9161337691879060040161529d565b602060405180830381600087803b15801561339057600080fd5b505af11580156133a4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506133c89190810190615083565b505b81156133e5576133da8683613b0f565b6133e5868386613b50565b50935093915050565b606063b65a25b960e01b826040516024016128a59190615224565b606063e946c1bb60e01b84848460405160240161342893929190615380565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff000000000000000000000000000000000000000000000000000000009093169290921790915290509392505050565b606063a6bcde4760e01b83836040516024016120c7929190615372565b8067ffffffffffffffff81168114610bef57610bef610982600184613913565b8051825460408301516020909301516bffffffffffffffffffffffff90811668010000000000000000027fffffffffffffffffffffffff000000000000000000000000ffffffffffffffff91909416740100000000000000000000000000000000000000000273ffffffffffffffffffffffffffffffffffffffff67ffffffffffffffff9094167fffffffffffffffffffffffffffffffffffffffffffffffff000000000000000090931692909217929092161716179055565b6060631de45ad160e01b83836040516024016120c7929190615245565b60408051808201909152600481527f57654fe400000000000000000000000000000000000000000000000000000000602082015290565b606063de16f1a060e01b826040516024016128a59190615224565b6000818152600a602052604090205473ffffffffffffffffffffffffffffffffffffffff16610e4c57610e4c610982826000613c39565b613653614ede565b61365c836122ea565b9050613686611c498383604001516bffffffffffffffffffffffff1661215490919063ffffffff16565b6bffffffffffffffffffffffff16604082015261118d83826134eb565b6136ab614ede565b6136b4836122ea565b9050613686611c498383604001516bffffffffffffffffffffffff1661286e90919063ffffffff16565b1460011690565b60606382ded78560e01b83836040516024016120c792919061529d565b60606322df959760e01b848484604051602401613428939291906153ec565b606063e9f8377160e01b83836040516024016120c7929190615372565b606063140a84db60e01b83836040516024016120c7929190615245565b60606331d7a50560e01b83836040516024016120c7929190615372565b60006131ea8361378e868563ffffffff613c5616565b9063ffffffff613c8716565b600c546000906137b190600163ffffffff61215416565b90506137bb614efe565b50600082815260156020908152604080832084845282529182902082516060810184528154808252600183015493820193909352600290910154928101929092521561118d5761118d6109828484613cb1565b6000828152600b602052604090205461382d908263ffffffff61215416565b6000838152600b602052604090205560175461384f908263ffffffff61215416565b6017555050565b610e4c8160006001613b50565b60006131ea8361378e61387d82600163ffffffff61215416565b61388d888763ffffffff613c5616565b9063ffffffff61286e16565b600d5415611b4557611b456109826000613cce565b601154158015906138c6575060125463ffffffff1615155b80156138d3575060135415155b80156138e6575060145463ffffffff1615155b80156139015750601454640100000000900463ffffffff1615155b15611b4557611b456109826001613cce565b606063c996af7b60e01b83836040516024016120c79291906153a2565b600082158061393d575081155b1561394a575060006131ea565b600061395d85600163ffffffff61215416565b865167ffffffffffffffff16101561397957856040015161397f565b85602001515b6bffffffffffffffffffffffff1690508061399e5760009150506131ea565b6139a9848483613778565b9695505050505050565b60008315806139c157508183145b156139ce575060006131ea565b818310613a07576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161172490615413565b613a0f614f5a565b613a198685613d0d565b9050613a23614f5a565b613a2d8785613d0d565b9050611d3d81600001518260200151846000015185602001518a613e2b565b600080613a598888613eb7565b90506000613a678787613eb7565b9050811580613a74575080155b15613a85575060009150611d3d9050565b600081831315613a9e57613a998284613f09565b613aa8565b613aa88383613f09565b9050613ad1613acc613ab983613f28565b8863ffffffff168863ffffffff166145ca565b6145d9565b905081831315613aea57613ae58282613f09565b613af4565b613af48282614bc3565b9050613b00818c614bef565b9b9a5050505050505050505050565b6000828152600b6020526040902054613b2e908263ffffffff61286e16565b6000838152600b602052604090205560175461384f908263ffffffff61286e16565b6000838152600f6020526040902054600c5480821415613b7157505061118d565b613b79614f5a565b506000858152600e602090815260408083208584528252918290208251808401909352805483526001015490820152613bb0614f5a565b613bb982614c31565b15613bf257613bd2826000015183602001518888614c3a565b60208301819052818352613be69190614c9c565b60208301528152613bfd565b602081018590528581525b6000878152600e6020908152604080832086845282528083208451815593820151600190940193909355978152600f9097529095205550505050565b6060639ae94f0160e01b83836040516024016120c7929190615362565b600082613c6557506000610ea8565b82820282848281613c7257fe5b0414610ea557610ea561098260018686613409565b600081613c9d57613c9d61098260038585613409565b6000828481613ca857fe5b04949350505050565b6060635caa0b0560e01b83836040516024016120c7929190615372565b60607f0b02d77300000000000000000000000000000000000000000000000000000000826001811115613cfd57fe5b6040516024016128a591906155d4565b613d15614f5a565b506000828152600e602090815260408083208484528252918290208251808401909352805483526001015490820152613d4d81614c31565b15613d5757610ea8565b6000613d6a83600163ffffffff61215416565b6000858152600e60209081526040808320848452825291829020825180840190935280548352600101549082015292509050613da582614c31565b15613db05750610ea8565b6000848152600f602052604090205483811015613e0d576000858152600e6020908152604080832084845282529182902082518084019093528054835260010154908201529250613e0083614c31565b15613e0d5750610ea89050565b50506040805180820190915260008152600160208201529392505050565b600081613e3a57506000613eae565b83613e5a57613e538561378e848963ffffffff613c5616565b9050613eae565b6000613e7f613e6f868863ffffffff613c5616565b61229b898763ffffffff613c5616565b90506000613e93828663ffffffff613c8716565b9050613ea98761378e868463ffffffff613c5616565b925050505b95945050505050565b600080831215613ecf57613ecf610982600185614cc5565b6000821215613ee657613ee6610982600184614cc5565b610ea5613f03846f80000000000000000000000000000000614d06565b83614d4e565b6000610ea5613f03846f80000000000000000000000000000000614d06565b60006f80000000000000000000000000000000821315613f5057613f50610982600184614dcf565b60008213613f6657613f66610982600084614dcf565b6f80000000000000000000000000000000821415613f8657506000610bef565b640733048c5a8213613fb957507fffffffffffffffffffffffffffffffe010000000000000000000000000000000610bef565b60008060006a01c8464f761647600000008513614018577ffffffffffffffffffffffffffffffff000000000000000000000000000000000909301926a01c8464f761647600000006f8000000000000000000000000000000086020594505b6cf1aaddd7742e900000000000008513614076577ffffffffffffffffffffffffffffffff800000000000000000000000000000000909301926cf1aaddd7742e900000000000006f8000000000000000000000000000000086020594505b6e0afe10820813d7800000000000000085136140d8577ffffffffffffffffffffffffffffffffc00000000000000000000000000000000909301926e0afe10820813d780000000000000006f8000000000000000000000000000000086020594505b6f02582ab704279ec00000000000000000851361413c577ffffffffffffffffffffffffffffffffe00000000000000000000000000000000909301926f02582ab704279ec000000000000000006f8000000000000000000000000000000086020594505b6f1152aaa3bf81cc00000000000000000085136141a0577fffffffffffffffffffffffffffffffff00000000000000000000000000000000909301926f1152aaa3bf81cc0000000000000000006f8000000000000000000000000000000086020594505b6f2f16ac6c59de700000000000000000008513614204577fffffffffffffffffffffffffffffffff80000000000000000000000000000000909301926f2f16ac6c59de700000000000000000006f8000000000000000000000000000000086020594505b6f4da2cbf1be58280000000000000000008513614268577fffffffffffffffffffffffffffffffffc0000000000000000000000000000000909301926f4da2cbf1be58280000000000000000006f8000000000000000000000000000000086020594505b6f63afbe7ab2082c00000000000000000085136142cc577fffffffffffffffffffffffffffffffffe0000000000000000000000000000000909301926f63afbe7ab2082c0000000000000000006f8000000000000000000000000000000086020594505b6f70f5a893b608861e1f58934f97aea57d8513614330577ffffffffffffffffffffffffffffffffff0000000000000000000000000000000909301926f70f5a893b608861e1f58934f97aea57d6f8000000000000000000000000000000086020594505b7fffffffffffffffffffffffffffffffff80000000000000000000000000000000850192508291506f80000000000000000000000000000000828002059050700100000000000000000000000000000000838103830205840193506f80000000000000000000000000000000818302816143a657fe5b059150700200000000000000000000000000000000836faaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa038302816143d757fe5b05840193506f80000000000000000000000000000000818302816143f757fe5b059150700300000000000000000000000000000000836f999999999999999999999999999999990383028161442857fe5b05840193506f800000000000000000000000000000008183028161444857fe5b059150700400000000000000000000000000000000836f924924924924924924924924924924920383028161447957fe5b05840193506f800000000000000000000000000000008183028161449957fe5b059150700500000000000000000000000000000000836f8e38e38e38e38e38e38e38e38e38e38e038302816144ca57fe5b05840193506f80000000000000000000000000000000818302816144ea57fe5b059150700600000000000000000000000000000000836f8ba2e8ba2e8ba2e8ba2e8ba2e8ba2e8b0383028161451b57fe5b05840193506f800000000000000000000000000000008183028161453b57fe5b059150700700000000000000000000000000000000836f89d89d89d89d89d89d89d89d89d89d890383028161456c57fe5b05840193506f800000000000000000000000000000008183028161458c57fe5b059150700800000000000000000000000000000000836f88888888888888888888888888888888038302816145bd57fe5b0584019350505050919050565b60006131ea613f038585614d06565b60007fffffffffffffffffffffffffffffffe01000000000000000000000000000000082121561460b57506000610bef565b8161462757506f80000000000000000000000000000000610bef565b600082131561463e5761463e610982600184614dcf565b6f800000000000000000000000000000006f1000000000000000000000000000000083078080028290056710e1b3be415a0000810293909301929091818302059050806705a0913f6b1e000002830192506f80000000000000000000000000000000828202816146aa57fe5b05905080670168244fdac7800002830192506f80000000000000000000000000000000828202816146d757fe5b05905080664807432bc1800002830192506f800000000000000000000000000000008282028161470357fe5b05905080660c0135dca0400002830192506f800000000000000000000000000000008282028161472f57fe5b059050806601b707b1cdc00002830192506f800000000000000000000000000000008282028161475b57fe5b059050806536e0f639b80002830192506f800000000000000000000000000000008282028161478657fe5b05905080650618fee9f80002830192506f80000000000000000000000000000000828202816147b157fe5b05905080649c197dcc0002830192506f80000000000000000000000000000000828202816147db57fe5b05905080640e30dce40002830192506f800000000000000000000000000000008282028161480557fe5b0590508064012ebd130002830192506f800000000000000000000000000000008282028161482f57fe5b059050806317499f0002830192506f800000000000000000000000000000008282028161485857fe5b059050806301a9d48002830192506f800000000000000000000000000000008282028161488157fe5b05905080621c638002830192506f80000000000000000000000000000000828202816148a957fe5b059050806201c63802830192506f80000000000000000000000000000000828202816148d157fe5b05905080611ab802830192506f80000000000000000000000000000000828202816148f857fe5b0590508061017c02830192506f800000000000000000000000000000008282028161491f57fe5b05905080601402830192506f800000000000000000000000000000008282028161494557fe5b600095909503946721c3677c82b400009190059384010582016f80000000000000000000000000000000019290507010000000000000000000000000000000008416156149b4577243cbaf42a000812488fc5c220ad7b97bf6e99e6cf1aaddd7742e56d32fb9f9974484020592505b7008000000000000000000000000000000008416156149f6577105d27a9f51c31b7c2f8038212a05747799916e0afe10820813d65dfe6a33c07f738f84020592505b700400000000000000000000000000000000841615614a3857701b4c902e273a58678d6d3bfdb93db96d026f02582ab704279e8efd15e0265855c47a84020592505b700200000000000000000000000000000000841615614a7a577003b1cc971a9bb5b9867477440d6d1577506f1152aaa3bf81cb9fdb76eae12d02957184020592505b700100000000000000000000000000000000841615614abc5770015bf0a8b1457695355fb8ac404e7a79e36f2f16ac6c59de6f8d5d6f63c1482a7c8684020592505b6f80000000000000000000000000000000841615614afc576fd3094c70f034de4b96ff7d5b6f99fcd86f4da2cbf1be5827f9eb3ad1aa9866ebb384020592505b6f40000000000000000000000000000000841615614b3c576fa45af1e1f40c333b3de1db4dd55f29a76f63afbe7ab2082ba1a0ae5e4eb1b479dc84020592505b6f20000000000000000000000000000000841615614b7c576f910b022db7ae67ce76b441c27035c6a16f70f5a893b608861e1f58934f97aea57d84020592505b6f10000000000000000000000000000000841615614bbc576f88415abbe9a76bead8d00cf112e4d4a86f783eafef1c0a8f3978c7f81824d62ebf84020592505b5050919050565b60006f80000000000000000000000000000000614be08484614d06565b81614be757fe5b059392505050565b600080821215614c0757614c07610982600184614cc5565b6000614c138484614d06565b905060008113614c27576000915050610ea8565b607f1c9392505050565b60200151151590565b60008085614c4c575082905081614c93565b83614c5b575084905083614c93565b614c7e614c6e858763ffffffff613c5616565b61388d888663ffffffff613c5616565b9150614c90858463ffffffff613c5616565b90505b94509492505050565b600080614cba84846f80000000000000000000000000000000614dfe565b915091509250929050565b60607fbd79545f00000000000000000000000000000000000000000000000000000000836001811115614cf457fe5b836040516024016120c79291906155e2565b600082614d1557506000610ea8565b5081810281838281614d2357fe5b05141580614d3a575082828281614d3657fe5b0514155b15610ea857610ea861098260018585614e6c565b600081614d6457614d6461098260028585614e6c565b7f800000000000000000000000000000000000000000000000000000000000000083148015614db25750817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff145b15614dc657614dc661098260038585614e6c565b818381614be757fe5b60607fed2f26a100000000000000000000000000000000000000000000000000000000836001811115614cf457fe5b60008082851180614e0e57508284115b15614e6357600084861015614e235784614e25565b855b9050614e37818563ffffffff613c8716565b9050614e49868263ffffffff613c8716565b9250614e5b858263ffffffff613c8716565b91505061303b565b50929391925050565b60607f8c12dfe700000000000000000000000000000000000000000000000000000000846003811115614e9b57fe5b8484604051602401613428939291906155f5565b6040518060a0016040528060008152602001600081526020016000815260200160008152602001600081525090565b604080516060810182526000808252602082018190529181019190915290565b60405180606001604052806000815260200160008152602001600081525090565b604080518082019091526000808252602082015290565b81548183558181111561118d5760008381526020902061118d918101908301614f74565b604051806040016040528060008152602001600081525090565b610b5791905b80821115614f8e5760008155600101614f7a565b5090565b803573ffffffffffffffffffffffffffffffffffffffff81168114610ea857600080fd5b60006040828403121561238a578081fd5b600060208284031215614fd8578081fd5b610ea58383614f92565b600080600060608486031215614ff6578182fd5b83356150018161561a565b925060208401356150118161561a565b929592945050506040919091013590565b60008060408385031215615034578182fd5b61503e8484614f92565b946020939093013593505050565b6000806040838503121561505e578182fd5b6150688484614f92565b915060208301356150788161564a565b809150509250929050565b600060208284031215615094578081fd5b8151610ea58161563c565b6000602082840312156150b0578081fd5b5035919050565b600080604083850312156150c9578182fd5b8235915060208301356150788161561a565b600080604083850312156150ed578182fd5b50508035926020909101359150565b6000806040838503121561510e578182fd5b82359150602083013563ffffffff81168114615078578182fd5b600060208284031215615139578081fd5b8135610ea58161564a565b600080600060a08486031215615158578283fd5b6151628585614fb6565b92506151718560408601614fb6565b9150608084013590509250925092565b600060208284031215615192578081fd5b5051919050565b600080600080600060a086880312156151b0578283fd5b8535945060208601356151c281615657565b93506040860135925060608601356151d981615657565b915060808601356151e981615657565b809150509295509295909350565b60008060408385031215615209578182fd5b823561521481615657565b915060208301356150788161563c565b73ffffffffffffffffffffffffffffffffffffffff91909116815260200190565b73ffffffffffffffffffffffffffffffffffffffff92831681529116602082015260400190565b73ffffffffffffffffffffffffffffffffffffffff9384168152919092166020820152604081019190915260600190565b73ffffffffffffffffffffffffffffffffffffffff929092168252602082015260400190565b602080825282518282018190526000918401906040840190835b8181101561531157835173ffffffffffffffffffffffffffffffffffffffff168352602093840193909201916001016152dd565b509095945050505050565b901515815260200190565b90815260200190565b92835273ffffffffffffffffffffffffffffffffffffffff91909116602083015263ffffffff16604082015260600190565b9182521515602082015260400190565b918252602082015260400190565b606081016004851061538e57fe5b938152602081019290925260409091015290565b60408101600384106153b057fe5b9281526020015290565b604081016153c784615610565b92815273ffffffffffffffffffffffffffffffffffffffff9190911660209091015290565b606081016153f985615610565b938152602081019290925263ffffffff1660409091015290565b60208082526013908201527f43525f494e54455256414c5f494e56414c494400000000000000000000000000604082015260600190565b60208082526014908201527f574554485f5452414e534645525f4641494c4544000000000000000000000000604082015260600190565b81518152602080830151908201526040918201519181019190915260600190565b815173ffffffffffffffffffffffffffffffffffffffff16815260209182015163ffffffff169181019190915260400190565b815167ffffffffffffffff1681526020808301516bffffffffffffffffffffffff90811691830191909152604092830151169181019190915260600190565b9283526020830191909152604082015260600190565b93845260208401929092526040830152606082015260800190565b948552602085019390935260408401919091526060830152608082015260a00190565b94855263ffffffff938416602086015260408501929092528216606084015216608082015260a00190565b92835260ff918216602084015216604082015260600190565b63ffffffff91909116815260200190565b63ffffffff92831681529116602082015260400190565b60ff91909116815260200190565b60ff929092168252602082015260400190565b60ff9390931683526020830191909152604082015260600190565b60028110610e4c57fe5b73ffffffffffffffffffffffffffffffffffffffff81168114610e4c57600080fd5b8015158114610e4c57600080fd5b60028110610e4c57600080fd5b63ffffffff81168114610e4c57600080fdfea365627a7a72315820006210cdecfe6b555e273506a51e8f70592803d6dba0c5040fa921b6f79ac2176c6578706572696d656e74616cf564736f6c634300050c0040

Deployed Bytecode Sourcemap

781:550:0:-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1793:417:2;;8:9:-1;5:2;;;30:1;27;20:12;5:2;-1:-1;1793:417:2;;;;;;;;:::i;:::-;;1303:1653:23;;8:9:-1;5:2;;;30:1;27;20:12;5:2;1303:1653:23;;;:::i;:::-;;;;;;;;;;;;;;;;2637:152:17;;8:9:-1;5:2;;;30:1;27;20:12;5:2;-1:-1;2637:152:17;;;;;;;;:::i;3430:84:5:-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;-1:-1;3430:84:5;;;;;;;;:::i;:::-;;;;;;;;;;1796:1176:16;;8:9:-1;5:2;;;30:1;27;20:12;5:2;-1:-1;1796:1176:16;;;;;;;;:::i;3680:75:5:-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;-1:-1;3680:75:5;;;;;;;;:::i;:::-;;;;;;;;;;;;2032:188:4;;8:9:-1;5:2;;;30:1;27;20:12;5:2;2032:188:4;;;:::i;:::-;;;;;;;;3485:245:17;;8:9:-1;5:2;;;30:1;27;20:12;5:2;-1:-1;3485:245:17;;;;;;;;:::i;:::-;;;;;;;;1275:131:46;;8:9:-1;5:2;;;30:1;27;20:12;5:2;-1:-1;1275:131:46;;;;;;;;:::i;2162:334:17:-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;-1:-1;2162:334:17;;;;;;;;:::i;4389:194:1:-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;-1:-1;4389:194:1;;;;;;;;:::i;:::-;;;;;;;;1055:28:46;;8:9:-1;5:2;;;30:1;27;20:12;5:2;-1:-1;1055:28:46;;;;;;;;:::i;3960:152:20:-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;-1:-1;3960:152:20;;;;;;;;:::i;:::-;;;;;;;;2303:45:5;;8:9:-1;5:2;;;30:1;27;20:12;5:2;2303:45:5;;;:::i;3302:1467:16:-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;-1:-1;3302:1467:16;;;;;;;;:::i;2664:47:5:-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;-1:-1;2664:47:5;;;;;;;;:::i;:::-;;;;;;;;2907:629:20;;8:9:-1;5:2;;;30:1;27;20:12;5:2;-1:-1;2907:629:20;;;;;;;;:::i;2652:619:24:-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;2652:619:24;;;:::i;:::-;;;;;;;;;;;;2401:173:4;;8:9:-1;5:2;;;30:1;27;20:12;5:2;2401:173:4;;;:::i;2789:37:5:-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;2789:37:5;;;:::i;1704:951:20:-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;-1:-1;1704:951:20;;;;;;;;:::i;1520:445:46:-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;-1:-1;1520:445:46;;;;;;;;:::i;2237:27:5:-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;2237:27:5;;;:::i;3107:39::-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;3107:39:5;;;:::i;:::-;;;;;;;;1264:414:2;;8:9:-1;5:2;;;30:1;27;20:12;5:2;-1:-1;1264:414:2;;;;;;;;:::i;749:20:55:-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;749:20:55;;;:::i;2138:195:46:-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;-1:-1;2138:195:46;;;;;;;;:::i;1464:675:24:-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;-1:-1;1464:675:24;;;;;;;;:::i;3021:31:5:-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;3021:31:5;;;:::i;1551:2690:1:-;;;;;;;;;:::i;1871:25:5:-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;1871:25:5;;;:::i;1064:467:16:-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;-1:-1;1064:467:16;;;;;;;;:::i;3851:41:5:-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;3851:41:5;;;:::i;1195:195:25:-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;1195:195:25;;;:::i;3645:232:20:-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;-1:-1;3645:232:20;;;;;;;;:::i;1110:140:21:-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;-1:-1;1110:140:21;;;;;;;;:::i;1006:43:46:-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;-1:-1;1006:43:46;;;;;;;;:::i;1416:742:21:-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;-1:-1;1416:742:21;;;;;;;;:::i;2158:51:5:-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;-1:-1;2158:51:5;;;;;;;;:::i;2430:138:46:-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;2430:138:46;;;:::i;:::-;;;;;;;;2904:40:5;;8:9:-1;5:2;;;30:1;27;20:12;5:2;2904:40:5;;;:::i;1072:257:0:-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;1072:257:0;;;:::i;1099:855:17:-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;-1:-1;1099:855:17;;;;;;;;:::i;3203:41:5:-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;3203:41:5;;;:::i;2375:759:21:-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;-1:-1;2375:759:21;;;;;;;;:::i;1049:30:5:-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;1049:30:5;;;:::i;1957:49::-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;-1:-1;1957:49:5;;;;;;;;:::i;3007:276:17:-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;-1:-1;3007:276:17;;;;;;;;:::i;928:329:55:-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;-1:-1;928:329:55;;;;;;;;:::i;3404:2420:23:-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;-1:-1;3404:2420:23;;;;;;;;:::i;1793:417:2:-;955:27:46;:25;:27::i;:::-;1897:20:2;;;;;;;:14;:20;;;;;;;;1892:238;;1933:186;1955:163;2014:68;2100:4;1955:41;:163::i;:::-;1933:21;:186::i;:::-;2139:20;;;2162:5;2139:20;;;:14;:20;;;;;;;:28;;;;;;2182:21;;;;;2154:4;;2182:21;;;;;;;;;;1793:417;:::o;1303:1653:23:-;1404:12;;1357:7;;;1446:24;1404:12;1468:1;1446:24;:21;:24;:::i;:::-;1547:39;1589:33;;;:22;:33;;;;;:52;;;1426:44;;-1:-1:-1;1655:36:23;;1651:273;;1707:206;1746:153;1819:9;1850:31;1746:51;:153::i;1707:206::-;2026:10;:8;:10::i;:::-;2165:26;:24;:26::i;:::-;2108:37;;;;:22;:37;;;;;:83;2201:47;;:::i;:::-;-1:-1:-1;2251:37:23;;;;:22;:37;;;;;;;;;2201:87;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2330:237;;2201:87;;2274:13;;2330:237;;;;2201:87;;;;2330:237;;;;;;;;;;2656:16;:14;:16::i;:::-;2761:34;;;;2757:141;;2854:32;;2821:66;;2836:13;;2821:66;;;;2851:1;;2821:66;;;;;;;;;;2757:141;2915:34;;;;-1:-1:-1;;;;1303:1653:23;;:::o;2637:152:17:-;2721:7;2751:13;:11;:13::i;:::-;:23;;;2775:6;2751:31;;;;;;;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;2751:31:17;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;2751:31:17;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;2751:31:17;;;;;;;;;2744:38;;2637:152;;;;:::o;3430:84:5:-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;1796:1176:16:-;1877:10;1898:48;;:::i;:::-;1981:68;;;:60;:68;;;:60;;:68;:60;:68;;1961:89;;:19;:89::i;:::-;1898:152;;2140:32;2175:129;2207:18;:38;;;2175:129;;2259:18;:35;;;2175:129;;:18;:129::i;:::-;2140:164;;2328:24;2319:6;:33;2315:254;;;2368:190;2407:137;2474:6;2502:24;2407:45;:137::i;2368:190::-;2657:68;;;:60;:68;;;:60;;:68;:60;:68;;2613:142;;2739:6;2613:30;:142::i;:::-;2822:13;:11;:13::i;:::-;:26;;;2849:6;2857;2822:42;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;2822:42:16;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;2822:42:16;;;;2929:6;2908:57;;;2949:6;2908:57;;;;;;;;;;;;;;;1796:1176;;;;:::o;3680:75:5:-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;2032:188:4:-;932:42;2032:188;:::o;3485:245:17:-;3584:37;;:::i;:::-;3667:31;;;;:23;:31;;;;;3647:52;;:19;:52::i;1275:131:46:-;882:22:55;:20;:22::i;:::-;1370:29:46;1392:6;1370:21;:29::i;:::-;1275:131;:::o;2162:334:17:-;2312:37;;:::i;:::-;2375:90;2408:19;:39;2434:11;2428:18;;;;;;;;2408:39;;;;;;;;;;;;;;;;-1:-1:-1;2408:39:17;;;:47;;;;;;;;;;2375:19;:90::i;:::-;2365:100;-1:-1:-1;2162:334:17;;;;;:::o;4389:194:1:-;4490:25;;:::i;:::-;-1:-1:-1;4538:24:1;;;;:16;:24;;;;;;;;4563:12;;4538:38;;;;;;;;4531:45;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4389:194::o;1055:28:46:-;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;1055:28:46;:::o;3960:152:20:-;4045:20;;:::i;:::-;-1:-1:-1;4088:17:20;;;;:9;:17;;;;;;;;;4081:24;;;;;;;;;;;;;;;;;;;;;;;;3960:152::o;2303:45:5:-;;;;:::o;3302:1467:16:-;3481:10;3565:11;3561:48;;3592:7;;;3561:48;3718:32;3703:11;;;;:4;:11;;;:47;;;;;;;;;:108;;;;-1:-1:-1;3779:32:16;3766:9;;;;:2;:9;;;:45;;;;;;;;;3703:108;3699:145;;;3827:7;;;3699:145;3902:30;3887:11;;;;:4;:11;;;:45;;;;;;;;;3883:183;;;3948:107;3982:4;:11;;;4011:6;4035;3948:16;:107::i;:::-;4093:30;4080:9;;;;:2;:9;;;:43;;;;;;;;;4076:177;;;4139:103;4171:2;:9;;;4198:6;4222;4139:14;:103::i;:::-;4287:38;4328:19;4287:38;4354:11;;;;:4;:11;;;4348:18;;;;;;;;4328:39;;;;;;;;;;;;;;;;-1:-1:-1;4328:39:16;;;:47;;;;;;;;;;;-1:-1:-1;;4424:19:16;;-1:-1:-1;;4450:9:16;;;;:2;:9;;;4444:16;;;;;;;;4424:37;;;;;;;;;;;;;;;;-1:-1:-1;4424:37:16;;;:45;;;;;;;;;;;-1:-1:-1;4479:80:16;4503:7;4424:45;4543:6;4479:10;:80::i;:::-;4743:9;;;;;;4688:11;;;;;4593:169;;;;;;4636:6;;4662:11;;4688:4;4662:11;;;4656:18;;;;;;;;4719:9;;;;:2;:9;;;4713:16;;;;;;;;4593:169;;;;;;;;;;;;;;;;;3302:1467;;;;;;;:::o;2664:47:5:-;;;;;;;;;;;;;;;:::o;2907:629:20:-;3039:6;1261:35;1289:6;1261:27;:35::i;:::-;3114:27;3144:17;;;:9;:17;;;;;:31;;;;;;3185:117;3144:17;:31;3276:16;3185:23;:117::i;:::-;3348:17;;;;:9;:17;;;;;;;:50;;;;;;;;;;;;3413:116;3348:17;;3413:116;;;;3469:20;;3348:50;;3413:116;;2652:619:24;2998:22;;3060:26;;3116:16;;3171:25;;2998:22;;3060:26;;;;;3116:16;;3171:25;;;;3237:27;;;;;2652:619::o;2401:173:4:-;1381:42;2401:173;:::o;2789:37:5:-;;;;:::o;1704:951:20:-;2012:10;;1812:14;;1910:10;;2004:30;;2032:1;2004:30;:27;:30;:::i;:::-;1983:10;:52;;;1996:39;-1:-1:-1;2088:134:20;1996:39;714:5:3;2199:13:20;2088:23;:134::i;:::-;2266:25;;:::i;:::-;-1:-1:-1;2294:99:20;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;2403:17:20;;;:9;:17;;;;;;:24;;;;;;;;;;;;;;;;;;;;;;;;;;;2484:51;;;;;;2403:17;;2294:99;;;;2484:51;;;;;;;;;;2550:18;2546:79;;;2584:30;2607:6;2584:22;:30::i;:::-;-1:-1:-1;;1704:951:20;;;;:::o;1520:445:46:-;882:22:55;:20;:22::i;:::-;1623:18:46;;;;;;;:10;:18;;;;;;;;1618:131;;1657:81;1679:58;1730:6;1679:50;:58::i;1657:81::-;1763:9;1758:201;1782:11;:18;1778:22;;1758:201;;;1843:6;1825:24;;:11;1837:1;1825:14;;;;;;;;;;;;;;;;;;;;:24;1821:128;;;1869:42;1901:6;1909:1;1869:31;:42::i;:::-;1929:5;;1821:128;1802:3;;1758:201;;;;1520:445;:::o;2237:27:5:-;;;;:::o;3107:39::-;;;;;;:::o;1264:414:2:-;955:27:46;:25;:27::i;:::-;1364:20:2;;;;;;;:14;:20;;;;;;;;1360:241;;;1400:190;1422:167;1481:72;1571:4;1422:41;:167::i;1400:190::-;1610:20;;;;;;;:14;:20;;;;;;;:27;;;;1633:4;1610:27;;;1652:19;;;;;1625:4;;1652:19;;749:20:55;;;;;;:::o;2138:195:46:-;882:22:55;:20;:22::i;:::-;2280:46:46;2312:6;2320:5;2280:31;:46::i;1464:675:24:-;955:27:46;:25;:27::i;:::-;1751:211:24;1775:23;1812:27;1853:17;1884:26;1924:28;1751:10;:211::i;:::-;2099:4;2077:53;;;:55;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;2077:55:24;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;2077:55:24;;;;1464:675;;;;;:::o;3021:31:5:-;;;;:::o;1551:2690:1:-;993:10:2;978:26;;;;:14;:26;;;;;;;;973:171;;1020:113;1042:90;1108:10;1042:48;:90::i;1020:113::-;1738:36:1;1762:11;1738:23;:36::i;:::-;1883:9;1879:274;;1938:17;:15;:17::i;:::-;:30;;;1990:12;2032:4;2059:11;1938:150;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;1938:150:1;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;1938:150:1;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;1938:150:1;;;;;;;;;1913:229;;;;;;;;;;;;;;;;;;;;;;2229:27;;;2212:14;2229:27;;;:13;:27;;;;;;2381:21;2377:58;;2418:7;;;2377:58;2445:17;2465:36;2494:6;2465:28;:36::i;:::-;:56;;;2445:76;;;;2588:16;;2576:9;:28;2572:65;;;2620:7;;;;2572:65;2742:12;;2718:21;2806:24;;;:16;:24;;;;;;;;:39;;;;;;;;2909:22;:37;;;;;;3082:26;;3122:24;3118:831;;3219:26;3247:27;3278:50;3310:6;3318:9;3278:31;:50::i;:::-;3342:25;;;:46;;;3402:26;;;:48;;;3555:37;;;;3218:110;;-1:-1:-1;3218:110:1;-1:-1:-1;3555:66:1;;3218:110;3555:66;:45;:66;:::i;:::-;3515:37;;;:106;3779:1;3733:37;;;;:48;;;:45;:48;:::i;:::-;3693:37;;;:88;3884:54;;3931:6;;3916:13;;3884:54;;;;;3118:831;;;4028:40;:19;4056:11;4028:40;:27;:40;:::i;:::-;3999:69;;4176:37;;;;:58;;4222:11;4176:58;:45;:58;:::i;:::-;4136:18;:37;;:98;;;;1153:1:2;;;;;;1551:2690:1;;;:::o;1871:25:5:-;;;;:::o;1064:467:16:-;1143:10;1219:13;:11;:13::i;:::-;:25;;;1245:6;1253;1219:41;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;1219:41:16;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;-1:-1;;;;1337:68:16;;;:60;:68;;;:60;;:68;:60;:68;;1293:142;;1419:6;1293:30;:142::i;:::-;1488:6;1469:55;;;1508:6;1469:55;;;;;;;;;;;;;;;1064:467;;:::o;3851:41:5:-;;;;:::o;1195:195:25:-;1291:7;1321:62;1360:22;;1321:30;;:38;;:62;;;;:::i;:::-;1314:69;;1195:195;:::o;3645:232:20:-;3738:10;3722:13;3758:20;;;:13;:20;;;;;;:29;;;3802:68;3781:6;;3738:10;;3802:68;;3722:13;3802:68;3645:232;;:::o;1110:140:21:-;1191:52;1224:6;1232:10;1191:32;:52::i;1006:43:46:-;;;;;;;;;;;;;;;:::o;1416:742:21:-;1519:14;1716:25;;:::i;:::-;-1:-1:-1;1744:17:21;;;;:9;:17;;;;;;;;1716:45;;;;;;;;;;;;;;;;;;;;;;;;;;;1744:17;1892:34;1744:17;1892:26;:34::i;:::-;1811:115;;;;1988:140;2026:4;:18;;;2058:23;2095;1988:24;:140::i;:::-;-1:-1:-1;1976:152:21;1416:742;-1:-1:-1;;;;;1416:742:21:o;2158:51:5:-;;;;;;;;;;;;;:::o;2430:138:46:-;2511:16;2550:11;2543:18;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2430:138;:::o;2904:40:5:-;;;;;;:::o;1072:257:0:-;955:27:46;:25;:27::i;:::-;1273:21:0;:19;:21::i;:::-;1304:18;:16;:18::i;:::-;1072:257::o;1099:855:17:-;1212:37;;:::i;:::-;1335:30;1308:59;;:20;:59;;1275:102;1308:59;1275:19;:102::i;:::-;1265:112;-1:-1:-1;1406:32:17;1391:11;:47;;;;;;;;;1387:537;;;1645:18;1666:13;:11;:13::i;:::-;:31;;;:33;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;1666:33:17;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;1666:33:17;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;1666:33:17;;;;;;;;;1645:54;;1743:66;:47;1762:7;:27;;;1743:47;;:10;:18;;:47;;;;:::i;:::-;:64;:66::i;:::-;1713:96;;;;:27;;;:96;1869:24;;;;1850:63;;:44;;:10;;:44;;:18;:44;:::i;:63::-;1823:90;;:24;;;:90;-1:-1:-1;1099:855:17;;;:::o;3203:41:5:-;;;;;;;;;:::o;2375:759:21:-;2495:14;2525:25;;:::i;:::-;-1:-1:-1;2553:17:21;;;;:9;:17;;;;;;;;2525:45;;;;;;;;;;;;;;;;;;;;;;;;;;;2553:17;2701:34;2553:17;2701:26;:34::i;:::-;2620:115;;;;2786:32;2822:140;2860:4;:18;;;2892:23;2929;2822:24;:140::i;:::-;2783:179;;;2979:148;3016:6;3036;3056:24;3094:23;2979;:148::i;:::-;2972:155;2375:759;-1:-1:-1;;;;;;;2375:759:21:o;1049:30:5:-;;;;;;:::o;1957:49::-;;;;;;;;;;;;;:::o;3007:276:17:-;3124:37;;:::i;:::-;3207:36;;;;;;;:28;:36;;;;;;;;:44;;;;;;;;3187:65;;:19;:65::i;928:329:55:-;882:22;:20;:22::i;:::-;1024;;;1020:231;;1062:70;1084:47;:45;:47::i;1062:70::-;1020:231;;;1163:5;:16;;;;;;;;;;;;1198:42;;1163:16;;1219:10;;1198:42;;1163:5;1198:42;928:329;:::o;3404:2420:23:-;3532:12;;3508:21;3574:24;3532:12;3596:1;3574:24;:21;:24;:::i;:::-;3554:44;;3689:47;;:::i;:::-;-1:-1:-1;3739:33:23;;;;:22;:33;;;;;;;;;3689:83;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;3782:76;;3841:7;;;;;3782:76;3953:35;;:::i;:::-;-1:-1:-1;3991:24:23;;;;:16;:24;;;;;;;;:35;;;;;;;;;3953:73;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4036:65;;4084:7;;;;;;4036:65;4216:24;;;;:16;:24;;;;;;;;:35;;;;;;;;4209:42;;;;;;;;;;;;;;4312:67;4352:9;4363:15;4312:39;:67::i;:::-;4294:85;;4576:22;4600:21;4625:103;4655:6;4675:7;4696:9;:22;;;4625:16;:103::i;:::-;4575:153;;;;4822:6;4795:13;4770:123;4842:14;4870:13;4770:123;;;;;;;;;;;;;;;;4904:19;4926:37;:14;4949:13;4926:37;:22;:37;:::i;:::-;5141;;;;4904:59;;-1:-1:-1;5141:58:23;;4904:59;5141:58;:45;:58;:::i;:::-;5089:37;;;:110;;;5019:33;;;;:22;:33;;;;;;;;:55;;:180;;;;5384:34;;;:45;;5427:1;5384:45;:42;:45;:::i;:::-;5335:34;;;;:94;;;5268:33;;;;:22;:33;;;;;;;:52;;:161;;;;5540:34;5536:282;;5659:37;;;;5714:32;;5632:9;;5600:207;;5714:79;;5659:37;5714:79;:40;:79;:::i;:::-;5600:207;;;;;;;;;;;;;;;;3404:2420;;;;;;;;;:::o;2628:226:46:-;2725:10;2714:22;;;;:10;:22;;;;;;;;2709:139;;2752:85;2774:62;2825:10;2774:50;:62::i;4182:334:15:-;4344:12;1593:10;4415:31;;4460:10;4484:15;4379:130;;;;;;;;;;;;;;22:32:-1;26:21;;;22:32;6:49;;4379:130:15;;;49:4:-1;25:18;;61:17;;4379:130:15;182:15:-1;4379:130:15;;;;179:29:-1;;;;160:49;;;4379:130:15;-1:-1:-1;4182:334:15;;;;:::o;1511:170:52:-;1654:9;1648:16;1641:4;1630:9;1626:20;1619:46;965:364:53;1051:7;1082:1;1078;:5;1074:227;;;1099:191;1121:168;1178:59;1255:1;1274;1121:39;:168::i;1099:191::-;-1:-1:-1;1317:5:53;;;965:364::o;7958:370:15:-;8128:12;3687:10;8199:43;;8256:16;8286:25;8163:158;;;;;;;;;;6709:200:23;6789:4;6781:21;6816:15;;6812:91;;6847:17;:15;:17::i;:::-;:25;;;6879:10;6847:45;;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;6847:45:23;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;6847:45:23;;;;;6709:200;:::o;7043:259::-;7126:19;7175:91;7239:26;;7175:17;:15;:17::i;:::-;:27;;;7211:4;7175:42;;;;;;;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;7175:42:23;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;7175:42:23;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;7175:42:23;;;;;;;;;:63;:91;:63;:91;:::i;2012:741:25:-;2188:15;2156:29;2297:41;:39;:41::i;:::-;2274:64;;2367:21;2352:12;:36;2348:219;;;2404:152;2426:129;2490:12;2520:21;2426:46;:129::i;2404:152::-;2625:12;;2605:17;;2625:23;;2646:1;2625:23;:20;:23;:::i;:::-;2658:12;:24;-1:-1:-1;;2692:30:25;:54;2012:741::o;2569:468:18:-;2688:37;;:::i;:::-;-1:-1:-1;2741:20:18;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2795:12;;2741:20;;2821:36;;2817:190;;;2896:32;:13;:30;:32::i;:::-;2873:55;;;;2972:24;;;;2942:54;;:27;;;:54;2817:190;-1:-1:-1;2569:468:18;;;:::o;1866:135:53:-;1951:7;1985:1;1981;:5;:13;;1993:1;1981:13;;;-1:-1:-1;1989:1:53;;1974:20;-1:-1:-1;1866:135:53:o;4522:300:15:-;4658:12;1751:10;4729:35;;4778:6;4798:7;4693:122;;;;;;;;;;3873:530:18;4040:37;;:::i;:::-;4080:31;4100:10;4080:19;:31::i;:::-;4040:71;;4148:68;:49;4190:6;4156:7;:24;;;4148:33;;:41;;:49;;;;:::i;:68::-;4121:95;;;;:24;;;:95;4264:27;;;;4256:71;;:52;;:36;4301:6;4256:52;:44;:52;:::i;:71::-;4226:101;;:27;;;:101;4362:34;4376:10;4226:7;4362:13;:34::i;1263:255:55:-;1357:5;;;;1343:10;:19;1339:173;;1481:5;;1378:123;;1400:100;;1453:10;;1481:5;;1400:35;:100::i;2940:602:46:-;3081:20;;;3077:127;;3117:76;3139:53;:51;:53::i;3117:76::-;3279:18;;;;;;;:10;:18;;;;;;;;3275:134;;;3313:85;3335:62;3390:6;3335:54;:62::i;3313:85::-;3419:18;;;;;;;3440:4;3419:18;;;;;;;;:25;;;;;;;;3454:11;27:10:-1;;23:18;;;45:23;;3454:24:46;;;;;;;;;;;;;;3493:42;3524:10;;3419:18;3493:42;;;2940:602;:::o;6099:923:16:-;6297:32;6322:6;6297:24;:32::i;:::-;6340:82;6386:6;6406;6340:32;:82::i;:::-;6546:36;;;;;;;:28;:36;;;;;;;;:44;;;;;;;;6512:108;;6604:6;6512:20;:108::i;:::-;6728:31;;;;:23;:31;;;;;6694:95;;6773:6;6694:20;:95::i;:::-;6953:30;6926:59;;:20;:59;;6892:123;6926:59;6999:6;6892:20;:123::i;4983:886::-;5176:32;5201:6;5176:24;:32::i;:::-;5219:82;5265:6;5285;5219:32;:82::i;:::-;5425:36;;;;;;;:28;:36;;;;;;;;:44;;;;;;;;5391:108;;5483:6;5391:20;:108::i;:::-;5607:31;;;;:23;:31;;;;;5573:95;;5652:6;5573:20;:95::i;:::-;5800:30;5773:59;;:20;:59;;5739:123;5773:59;5846:6;5739:20;:123::i;1268:1121:18:-;1491:33;1509:7;1518:5;1491:17;:33::i;:::-;1487:70;;;1540:7;;1487:70;1613:34;;:::i;:::-;1650:28;1670:7;1650:19;:28::i;:::-;1613:65;;1688:32;;:::i;:::-;1723:26;1743:5;1723:19;:26::i;:::-;1688:61;;1808:4;:21;;;1799:30;;:6;:30;1795:248;;;1845:187;1884:134;1951:6;1979:4;:21;;;1884:134;;:45;:134::i;1845:187::-;2122:21;;;;2114:65;;:46;;:30;;2153:6;2114:46;:38;:46;:::i;:65::-;2090:89;;;;:21;;;;:89;;;;2219:19;;;2211:63;;:44;;:28;2248:6;2211:44;:36;:44;:::i;:63::-;2189:85;;:19;;;:85;2320:28;2334:7;2343:4;2320:13;:28::i;:::-;2358:24;2372:5;2379:2;2358:13;:24::i;:::-;1268:1121;;;;;:::o;5894:393:20:-;5990:16;6009:17;;;:9;:17;;;;;:26;;;6049:10;:22;;6045:236;;6087:183;6126:130;6200:10;6232:6;6126:52;:130::i;4842:919::-;714:5:3;5047:34:20;;;;5043:712;;;5152:218;5174:195;5231:66;5315:6;5339:16;5174:39;:195::i;5152:218::-;5043:712;;;5410:20;5391:39;;:16;:39;;;5387:368;;;5519:225;5541:202;5598:73;5689:6;5713:16;5541:39;:202::i;1335:383:53:-;1421:7;1456:5;;;1475;;;1471:223;;;1496:187;1518:164;1575:55;1648:1;1667;1518:39;:164::i;2747:241:47:-;2844:12;1416:10;2915:36;;2965:6;2879:102;;;;;;;;;;;;;22:32:-1;26:21;;;22:32;6:49;;2879:102:47;;;49:4:-1;25:18;;61:17;;2879:102:47;182:15:-1;2879:102:47;;;;179:29:-1;;;;160:49;;;2879:102:47;-1:-1:-1;2747:241:47;;;:::o;3715:887:46:-;3845:18;;;;;;;:10;:18;;;;;;;;3840:131;;3879:81;3901:58;3952:6;3901:50;:58::i;3879:81::-;3993:11;:18;3984:27;;3980:201;;4027:143;4049:120;4114:5;4137:11;:18;;;;4049:47;:120::i;4027:143::-;4216:6;4194:28;;:11;4206:5;4194:18;;;;;;;;;;;;;;;;;;;;:28;4190:212;;4238:153;4260:130;4334:11;4346:5;4334:18;;;;;;;;;;;;;;;;;;;;4370:6;4260:56;:130::i;4238:153::-;4419:18;;;;;;;:10;:18;;;;;4412:25;;;;;;4468:11;4480:18;;:22;;;;4468:35;;;;;;;;;;;;;;;;4447:11;:18;;4468:35;;;;;4459:5;;4447:18;;;;;;;;;;;;;;;:56;;;;;;;;;;;;;;;4513:11;:23;;;;;;;;;:::i;:::-;-1:-1:-1;4551:44:46;;4584:10;;4551:44;;;;;;;;;3715:887;;:::o;5130:789:24:-;5394:22;:48;;;5452:26;:56;;;;;;;;;;;;;;5518:16;:36;;;5564:25;:54;;5628:58;;;;;;5564:54;;;;;;;;5628:58;;;;;;;5702:210;;;;;;5419:23;;5481:27;;5537:17;;5592:26;;5658:28;;5702:210;;;;;;;;;;5130:789;;;;;:::o;3900:276:15:-;4021:12;1445:10;4092:40;;4146:13;4056:113;;;;;;;;;5783:512:1;6047:11;6034:9;:24;;:42;;;;-1:-1:-1;6062:9:1;:14;;6034:42;6030:259;;;6092:186;6131:133;6204:11;6237:9;6131:51;:133::i;4909:681::-;5054:20;5181:17;;;:9;:17;;;;;:26;5054:20;;;;5137:100;;5181:26;;5191:6;5137:30;:100::i;:::-;:120;;;5113:144;;;-1:-1:-1;5283:33:1;:10;5113:144;5283:33;:18;:33;:::i;:::-;5424:26;;5268:48;;-1:-1:-1;5342:195:1;;5377:150;;5424:26;;714:5:3;5268:48:1;5377:29;:150::i;:::-;5342:13;;:195;:21;:195;:::i;:::-;5326:211;-1:-1:-1;;4909:681:1;;;;;:::o;3190:530:18:-;3357:37;;:::i;:::-;3397:31;3417:10;3397:19;:31::i;:::-;3357:71;;3465:68;:49;3507:6;3473:7;:24;;;3465:33;;:41;;:49;;;;:::i;:68::-;3438:95;;;;:24;;;:95;3581:27;;;;3573:71;;:52;;:36;3618:6;3573:52;:44;:52;:::i;3371:1313:21:-;3539:37;3569:6;3539:29;:37::i;:::-;3632:15;3650:205;3687:6;3707;3829:1;3844;3650:23;:205::i;:::-;4170:36;;;;;;;:28;:36;;;;;;;;:44;;;;;;;;3632:223;;-1:-1:-1;4150:65:21;;:19;:65::i;:::-;4091:36;;;;;;;;:28;:36;;;;;;;;:44;;;;;;;;;:124;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4264:12;;4260:236;;4340:37;4361:6;4369:7;4340:20;:37::i;:::-;4442:17;:15;:17::i;:::-;:26;;;4469:6;4477:7;4442:43;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;4442:43:21;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;4442:43:21;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;4442:43:21;;;;;;;;;;4260:236;4646:31;4670:6;4646:23;:31::i;6161:469:23:-;6273:14;6301:20;6346:17;6366:23;6387:1;6366:12;;:20;;:23;;;;:::i;:::-;6346:43;;6399:35;;:::i;:::-;-1:-1:-1;6437:24:23;;;;:16;:24;;;;;;;;:35;;;;;;;;6399:73;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6542:33;;;:22;:33;;;;;;6491:85;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6399:73;6491:85;;6399:73;;6491:39;:85::i;:::-;6482:94;;6601:9;:22;;;6586:37;;6161:469;;;;;:::o;6947:624:21:-;7123:22;;7188:17;7184:333;;7238:11;7221:28;;7184:333;;;7297:144;7343:22;;;714:5:3;7416:11:21;7297:28;:144::i;:::-;7280:161;-1:-1:-1;7471:35:21;:11;7280:161;7471:35;:19;:35;:::i;:::-;7455:51;;7184:333;6947:624;;;;;;:::o;1501:285:25:-;1625:32;:30;:32::i;:::-;1738:15;1705:30;:48;1778:1;1763:12;:16;1501:285::o;3334:669:24:-;3435:29;:27;:29::i;:::-;3537:7;3591:28;3657:21;3724:1;3773;3785:211;3537:7;3591:28;3657:21;3724:1;3773;3785:10;:211::i;876:395:14:-;995:1;1011:10;;;:15;;1007:240;;1042:194;1064:171;1124:78;1220:1;1064:42;:171::i;7937:1833:21:-;8207:12;;8153:14;;8229:44;;:::i;:::-;-1:-1:-1;8276:36:21;;;;;;;:28;:36;;;;;;;;:44;;;;;;;;;8229:91;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8548:44;;8544:83;;;8615:1;8608:8;;;;;;8544:83;8771:174;8819:14;8847:13;8874:24;8912:23;8771:34;:174::i;:::-;9106:27;;8762:183;;-1:-1:-1;9064:31:21;;9098:47;;:36;;9143:1;9098:47;:44;:47;:::i;:::-;9064:81;;9164:246;9192:208;9242:6;9266:14;:34;;;9192:208;;9318:14;:27;;;9192:208;;9363:23;9192:32;:208::i;:::-;9164:6;;:246;:14;:246;:::i;:::-;9155:255;;9510:229;9538:191;9588:6;9612:14;:31;;;9538:191;;9661:23;9702:13;9538:32;:191::i;9510:229::-;9501:238;-1:-1:-1;;;;7937:1833:21;;;;;;;:::o;669:159:51:-;787:34;;;;;;;;;;;;;;;;;669:159;:::o;8245:1186:23:-;8559:23;;8448:15;;8555:73;;8603:14;;8555:73;8758:32;;8804:23;;8841:34;;;;8889:23;;;;8926:34;;;;8974:25;;8718:332;;8758:32;8804:23;8841:34;8889:23;8926:34;8974:25;;;;;9013:27;;;;8718:26;:332::i;:::-;9294:37;;;;9253:32;;8708:342;;-1:-1:-1;9226:24:23;;9253:79;;;:40;:79;:::i;:::-;9226:106;;9365:7;9346:16;:26;9342:83;;;9398:16;9388:26;;9342:83;8245:1186;;;;;:::o;5352:993:21:-;5496:22;5520:21;5557:25;;:::i;:::-;-1:-1:-1;5585:17:21;;;;:9;:17;;;;;;;;;5557:45;;;;;;;;;;;;;;;;;;;;;;;;;5704:112;;5774:6;5794:12;5704:24;:112::i;:::-;5670:146;;-1:-1:-1;5670:146:21;-1:-1:-1;5831:18:21;;5827:173;;5932:17;:15;:17::i;:::-;5959:13;;5932:57;;;;;:26;;;;;;;;:57;;5974:14;;5932:57;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;5932:57:21;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;5932:57:21;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;5932:57:21;;;;;;;;;;5827:173;6014:17;;6010:280;;6095:43;6116:6;6124:13;6095:20;:43::i;:::-;6222:57;6243:6;6251:13;6266:12;6222:20;:57::i;:::-;-1:-1:-1;5352:993:21;;;;;;:::o;2245:241:47:-;2342:12;1106:10;2413:36;;2463:6;2377:102;;;;;;;;;731:322:54;884:12;196:10;955:28;;997:9;1020:1;1035;919:127;;;;;;;;;;;;;;;22:32:-1;26:21;;;22:32;6:49;;919:127:54;;;49:4:-1;25:18;;61:17;;919:127:54;182:15:-1;919:127:54;;;;179:29:-1;;;;160:49;;;919:127:54;-1:-1:-1;731:322:54;;;;;:::o;5163:344:15:-;5320:12;2088:10;5391:38;;5443:12;5469:21;5355:145;;;;;;;;;;1383:395:14;1502:1;1518:10;;;:15;;1514:240;;1549:194;1571:171;1631:78;1727:1;1571:42;:171::i;5717:510:18:-;6066:20;;6040:46;;6126:24;;;;6193:27;;;;;6096:54;6160:60;;;;;;6096:54;;;;;;;6040:46;;;;;;;;;;;;6096:54;;;;;6160:60;;;;5717:510::o;387:276:51:-;511:12;183:10;582:25;;621:6;641:5;546:110;;;;;;;;;;2994:161:47;3113:35;;;;;;;;;;;;;;;;;2994:161;:::o;2492:249::-;2593:12;1265:10;2664:40;;2718:6;2628:106;;;;;;;;;4215:408:20;879:42:3;4313:17:20;;;:9;:17;;;;;:26;:41;:26;4309:308;;4441:165;4480:112;4541:6;4569:5;4480:39;:112::i;5149:409:18:-;5306:37;;:::i;:::-;5346:31;5366:10;5346:19;:31::i;:::-;5306:71;;5414:68;:49;5456:6;5422:7;:24;;;5414:33;;:41;;:49;;;;:::i;:68::-;5387:95;;:24;;;:95;5517:34;5531:10;5387:7;5517:13;:34::i;4574:404::-;4726:37;;:::i;:::-;4766:31;4786:10;4766:19;:31::i;:::-;4726:71;;4834:68;:49;4876:6;4842:7;:24;;;4834:33;;:41;;:49;;;;:::i;6460:525::-;6832:38;6888:42;6811:133;;6460:525::o;4828:329:15:-;4977:12;1926:10;5048:45;;5107:13;5134:6;5012:138;;;;;;;;;;6203:367;6382:12;2763:10;6453:29;;6496:10;6520:6;6540:13;6417:146;;;;;;;;;;;1947:292:47;2078:12;955:10;2149:34;;2197:5;2216:6;2113:119;;;;;;;;;;1622:319;1767:12;801:10;1838:42;;1894:10;1918:6;1802:132;;;;;;;;;;6879:376:15;7052:12;3515:10;7123:43;;7180:23;7217:21;7087:161;;;;;;;;;;3189:300:44;3353:21;3406:46;3440:11;3406:25;:9;3424:6;3406:25;:17;:25;:::i;:::-;:33;:46;:33;:46;:::i;7446:542:23:-;7565:12;;7545:17;;7565:23;;7586:1;7565:23;:20;:23;:::i;:::-;7545:43;;7598:35;;:::i;:::-;-1:-1:-1;7636:24:23;;;;:16;:24;;;;;;;;:35;;;;;;;;;7598:73;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;7755:28;7751:231;;7799:172;7838:119;7902:6;7930:9;7838:42;:119::i;11907:245:21:-;12025:23;;;;:15;:23;;;;;;:39;;12057:6;12025:39;:31;:39;:::i;:::-;11999:23;;;;:15;:23;;;;;:65;12103:26;;:42;;12138:6;12103:42;:34;:42;:::i;:::-;12074:26;:71;-1:-1:-1;;11907:245:21:o;3955:293:19:-;4207:34;4228:6;4236:1;4239;4207:20;:34::i;3762:545:44:-;3925:21;4165:104;4257:11;4165:70;4212:22;4257:11;4232:1;4212:22;:19;:22;:::i;:::-;4165:25;:9;4183:6;4165:25;:17;:25;:::i;:::-;:46;:70;:46;:70;:::i;2868:369:25:-;2958:30;;:35;2954:277;;3009:211;3048:158;3110:78;3048:40;:158::i;4084:542:24:-;4171:22;;:27;;;;:74;;-1:-1:-1;4214:26:24;;;;:31;;4171:74;:111;;;;-1:-1:-1;4261:16:24;;:21;;4171:111;:157;;;;-1:-1:-1;4298:25:24;;;;:30;;4171:157;:205;;;;-1:-1:-1;4344:27:24;;;;;;;:32;;4171:205;4167:453;;;4401:208;4440:155;4502:75;4440:40;:155::i;1059:297:54:-;1199:12;344:10;1270:31;;1315:9;1338:1;1234:115;;;;;;;;;;10223:1151:21;10487:7;10609:29;;;:61;;-1:-1:-1;10642:28:21;;10609:61;10605:100;;;-1:-1:-1;10693:1:21;10686:8;;10605:100;10848:31;10913:24;:13;10935:1;10913:24;:21;:24;:::i;:::-;10882:27;;:55;;;;:150;;11001:14;:31;;;10882:150;;;10952:14;:34;;;10882:150;10848:184;;;-1:-1:-1;11098:28:21;11094:67;;11149:1;11142:8;;;;;11094:67;11216:151;11259:24;11297:23;11334;11216:29;:151::i;:::-;11209:158;10223:1151;-1:-1:-1;;;;;;10223:1151:21:o;4641:1006:19:-;4855:14;4968:28;;;:54;;;5014:8;5000:10;:22;4968:54;4964:93;;;-1:-1:-1;5045:1:19;5038:8;;4964:93;5121:8;5108:10;:21;5100:53;;;;;;;;;;;;;;5201:36;;:::i;:::-;5240:47;5268:6;5276:10;5240:27;:47::i;:::-;5201:86;;5297:34;;:::i;:::-;5334:45;5362:6;5370:8;5334:27;:45::i;:::-;5297:82;;5425:215;5467:9;:19;;;5500:9;:21;;;5535:11;:21;;;5570:11;:23;;;5607;5425:28;:215::i;1676:2058:11:-;1944:15;1975;1993:37;2014:4;2020:9;1993:20;:37::i;:::-;1975:55;;2040:17;2060:39;2081:5;2088:10;2060:20;:39::i;:::-;2040:59;-1:-1:-1;2113:13:11;;;:32;;-1:-1:-1;2130:15:11;;2113:32;2109:81;;;-1:-1:-1;2178:1:11;;-1:-1:-1;2161:18:11;;-1:-1:-1;2161:18:11;2109:81;2953:8;2976:10;2964:8;:22;;:128;;3054:38;3071:10;3083:8;3054:16;:38::i;:::-;2964:128;;;3001:38;3018:8;3028:10;3001:16;:38::i;:::-;2953:139;;3106:191;3136:151;3173:18;3189:1;3173:15;:18::i;:::-;3216:14;3209:22;;3256:16;3249:24;;3136:19;:151::i;:::-;3106:16;:191::i;:::-;3102:195;;3519:10;3507:8;:22;;:114;;3590:31;3607:10;3619:1;3590:16;:31::i;:::-;3507:114;;;3544:31;3561:10;3573:1;3544:16;:31::i;:::-;3503:118;;3690:37;3711:1;3714:12;3690:20;:37::i;:::-;3680:47;1676:2058;-1:-1:-1;;;;;;;;;;;1676:2058:11:o;11518:245:21:-;11636:23;;;;:15;:23;;;;;;:39;;11668:6;11636:39;:31;:39;:::i;:::-;11610:23;;;;:15;:23;;;;;:65;11714:26;;:42;;11749:6;11714:42;:34;:42;:::i;1932:1776:19:-;2218:23;2244:42;;;:34;:42;;;;;;2320:12;;2422:32;;;2418:69;;;2470:7;;;;2418:69;2497:51;;:::i;:::-;-1:-1:-1;2563:32:19;;;;:24;:32;;;;;;;;:49;;;;;;;;;2497:115;;;;;;;;;;;;;;;;;;;2664:41;;:::i;:::-;2719:50;2742:26;2719:22;:50::i;:::-;2715:790;;;2931:187;2965:26;:36;;;3019:26;:38;;;3075:6;3099:5;2931:16;:187::i;:::-;2899:28;;;2870:248;;;;;;3261:126;;2870:248;3261:22;:126::i;:::-;3229:28;;;3200:187;;;2715:790;;;3447:28;;;3418:76;;;;;;2715:790;3567:32;;;;:24;:32;;;;;;;;:47;;;;;;;;:66;;;;;;;;;;;;;;;;3643:42;;;:34;:42;;;;;;:58;-1:-1:-1;;;;1932:1776:19:o;6576:297:15:-;6709:12;2906:10;6780:29;;6823:6;6843:13;6744:122;;;;;;;;;;122:448:53;208:7;235:6;231:45;;-1:-1:-1;264:1:53;257:8;;231:45;297:5;;;301:1;297;:5;:1;316:5;;;;;:10;312:234;;342:193;364:170;421:61;500:1;519;364:39;:170::i;576:383::-;662:7;689:6;685:223;;711:186;733:163;790:54;862:1;881;733:39;:163::i;711:186::-;917:9;933:1;929;:5;;;;;;;576:383;-1:-1:-1;;;;576:383:53:o;8334:291:15:-;8465:12;3840:10;8536:33;;8583:6;8603:5;8500:118;;;;;;;;;;7261:249;7368:12;7439:29;7488:4;7482:11;;;;;;;;7403:100;;;;;;;;;6619:1136:19;6733:41;;:::i;:::-;-1:-1:-1;6858:32:19;;;;:24;:32;;;;;;;;:39;;;;;;;;;6839:58;;;;;;;;;;;;;;;;;;;6911:40;6839:58;6911:22;:40::i;:::-;6907:94;;;6967:23;;6907:94;7062:17;7082:16;:5;7096:1;7082:16;:13;:16;:::i;:::-;7127:32;;;;:24;:32;;;;;;;;:43;;;;;;;;;7108:62;;;;;;;;;;;;;;;;;;;;-1:-1:-1;7062:36:19;-1:-1:-1;7184:40:19;7108:62;7184:22;:40::i;:::-;7180:94;;;-1:-1:-1;7240:23:19;;7180:94;7352:23;7378:42;;;:34;:42;;;;;;7434:23;;;7430:237;;;7492:32;;;;:24;:32;;;;;;;;:49;;;;;;;;;7473:68;;;;;;;;;;;;;;;;;;;;-1:-1:-1;7559:40:19;7473:68;7559:22;:40::i;:::-;7555:102;;;-1:-1:-1;7619:23:19;;-1:-1:-1;7619:23:19;7555:102;-1:-1:-1;;7725:23:19;;;;;;;;;-1:-1:-1;7725:23:19;;7746:1;7725:23;;;;;6619:1136;-1:-1:-1;;;6619:1136:19:o;3284:588:50:-;3461:14;3495:6;3491:45;;-1:-1:-1;3524:1:50;3517:8;;3491:45;3549:7;3545:113;;3588:59;3644:2;3588:30;:1;3615:2;3588:30;:26;:30;:::i;:59::-;3579:68;-1:-1:-1;3572:75:50;;3545:113;3667:17;3687:64;3736:14;:2;3747;3736:14;:10;:14;:::i;:::-;3687:27;:2;3711;3687:27;:23;:27;:::i;:64::-;3667:84;-1:-1:-1;3761:11:50;3775:21;3667:84;3793:2;3775:21;:17;:21;:::i;:::-;3761:35;-1:-1:-1;3813:52:50;3862:2;3813:27;:1;3761:35;3813:27;:22;:27;:::i;:52::-;3806:59;;;;3284:588;;;;;;;;:::o;5112:582:12:-;5174:8;5217:1;5205;5198:21;5194:215;;;5235:163;5257:140;5316:48;5382:1;5257:41;:140::i;5235:163::-;5441:1;5429;5422:21;5418:215;;;5459:163;5481:140;5540:48;5606:1;5481:41;:140::i;5459:163::-;5646:41;5651:24;5663:1;839:66;5651:4;:24::i;:::-;5684:1;5646:4;:41::i;2570:112::-;2626:8;2650:25;2655:16;2660:1;839:66;2655:4;:16::i;5945:5424::-;5990:8;839:66;6014:1;:14;6010:206;;;6044:161;6066:138;6123:48;6189:1;6066:39;:138::i;6044:161::-;6234:1;6229;:6;6225:198;;6251:161;6273:138;6330:48;6396:1;6273:39;:138::i;6251:161::-;839:66;6436:1;:12;6432:51;;;-1:-1:-1;6471:1:12;6464:8;;6432:51;1318:66;6496:1;:15;6492:64;;-1:-1:-1;1498:75:12;6527:18;;6492:64;6566:8;6584;6602;6915:66;6903:1;:79;6899:316;;6998:79;;;;;7124:66;839;7103:11;;:88;7099:92;;6899:316;7259:66;7247:1;:79;7243:316;;7342:79;;;;;7468:66;839;7447:11;;:88;7443:92;;7243:316;7602:66;7590:1;:79;7586:314;;7685:79;;;;;7810:66;839;7789:11;;:88;7785:92;;7586:314;7943:66;7931:1;:79;7927:314;;8026:79;;;;;8151:66;839;8130:11;;:88;8126:92;;7927:314;8284:66;8272:1;:79;8268:314;;8367:79;;;;;8492:66;839;8471:11;;:88;8467:92;;8268:314;8625:66;8613:1;:79;8609:314;;8708:79;;;;;8833:66;8720;8812:11;;:88;8808:92;;8609:314;8968:66;8956:1;:79;8952:318;;9051:79;;;;;9178:66;839;9157:11;;:88;9153:92;;8952:318;9316:66;9304:1;:79;9300:320;;9399:79;;;;;9527:66;839;9506:11;;:88;9502:92;;9300:320;9667:66;9655:1;:79;9651:322;;9750:79;;;;;9879:66;839;9858:11;;:88;9854:92;;9651:322;10138:11;;;;-1:-1:-1;10138:11:12;;-1:-1:-1;839:66:12;10163:5;;;:15;;-1:-1:-1;10241:35:12;10198:39;;;10193:45;;:83;10188:88;;;;839:66;10286:1;10282;:5;:15;;;;;;10278:19;;10389:35;10384:1;10346:35;:39;10341:1;:45;:83;;;;;;10336:88;;;;839:66;10434:1;10430;:5;:15;;;;;;10426:19;;10537:35;10532:1;10494:35;:39;10489:1;:45;:83;;;;;;10484:88;;;;839:66;10582:1;10578;:5;:15;;;;;;10574:19;;10685:35;10680:1;10642:35;:39;10637:1;:45;:83;;;;;;10632:88;;;;839:66;10730:1;10726;:5;:15;;;;;;10722:19;;10833:35;10828:1;10790:35;:39;10785:1;:45;:83;;;;;;10780:88;;;;839:66;10878:1;10874;:5;:15;;;;;;10870:19;;10981:35;10976:1;10938:35;:39;10933:1;:45;:83;;;;;;10928:88;;;;839:66;11026:1;11022;:5;:15;;;;;;11018:19;;11129:35;11124:1;11086:35;:39;11081:1;:45;:83;;;;;;11076:88;;;;839:66;11174:1;11170;:5;:15;;;;;;11166:19;;11277:35;11272:1;11234:35;:39;11229:1;:45;:83;;;;;;11224:88;;;;5945:5424;;;;;;:::o;2754:119::-;2823:8;2847:19;2852:10;2857:1;2860;2852:4;:10::i;11466:5743::-;11512:8;1498:75;11536:15;;11532:105;;;-1:-1:-1;11625:1:12;11618:8;;11532:105;11650:6;11646:51;;-1:-1:-1;839:66:12;11672:14;;11646:51;1438:1;11710;:15;11706:207;;;11741:161;11763:138;11820:48;11886:1;11763:39;:138::i;11741:161::-;839:66;12382;12378:70;;12462:5;;;:15;;;12488:18;12484:22;;12479:27;;;;;12378:70;;12546:5;;;:15;12542:19;;12568:1;12572:18;12568:22;12563:27;;;;839:66;12634:1;12630;:5;:15;;;;;;12626:19;;12652:1;12656:18;12652:22;12647:27;;;;839:66;12718:1;12714;:5;:15;;;;;;12710:19;;12736:1;12740:18;12736:22;12731:27;;;;839:66;12802:1;12798;:5;:15;;;;;;12794:19;;12820:1;12824:18;12820:22;12815:27;;;;839:66;12886:1;12882;:5;:15;;;;;;12878:19;;12904:1;12908:18;12904:22;12899:27;;;;839:66;12970:1;12966;:5;:15;;;;;;12962:19;;12988:1;12992:18;12988:22;12983:27;;;;839:66;13054:1;13050;:5;:15;;;;;;13046:19;;13072:1;13076:18;13072:22;13067:27;;;;839:66;13138:1;13134;:5;:15;;;;;;13130:19;;13156:1;13160:18;13156:22;13151:27;;;;839:66;13222:1;13218;:5;:15;;;;;;13214:19;;13240:1;13244:18;13240:22;13235:27;;;;839:66;13306:1;13302;:5;:15;;;;;;13298:19;;13324:1;13328:18;13324:22;13319:27;;;;839:66;13390:1;13386;:5;:15;;;;;;13382:19;;13408:1;13412:18;13408:22;13403:27;;;;839:66;13474:1;13470;:5;:15;;;;;;13466:19;;13492:1;13496:18;13492:22;13487:27;;;;839:66;13558:1;13554;:5;:15;;;;;;13550:19;;13576:1;13580:18;13576:22;13571:27;;;;839:66;13642:1;13638;:5;:15;;;;;;13634:19;;13660:1;13664:18;13660:22;13655:27;;;;839:66;13726:1;13722;:5;:15;;;;;;13718:19;;13744:1;13748:18;13744:22;13739:27;;;;839:66;13810:1;13806;:5;:15;;;;;;13802:19;;13828:1;13832:18;13828:22;13823:27;;;;839:66;13894:1;13890;:5;:15;;;;;;13886:19;;13912:1;13916:18;13912:22;13907:27;;;;839:66;13978:1;13974;:5;:15;;;;;14208:2;;;;;;14062:18;13974:15;;;13991:27;;;14058:22;:26;;839:66;14058:36;;13974:15;-1:-1:-1;14255:66:12;14244:78;;14243:85;14239:304;;14452:66;14359;14348:78;;:171;14344:175;;14239:304;14587:66;14576:78;;14575:85;14571:304;;14784:66;14691;14680:78;;:171;14676:175;;14571:304;14918:66;14907:78;;14906:85;14902:303;;15115:66;15022;15011:78;;:171;15007:175;;14902:303;15248:66;15237:78;;15236:85;15232:303;;15445:66;15352;15341:78;;:171;15337:175;;15232:303;15578:66;15567:78;;15566:85;15562:303;;15775:66;15682;15671:78;;:171;15667:175;;15562:303;15908:66;15897:78;;15896:85;15892:303;;16105:66;16012;16001:78;;:171;15997:175;;15892:303;16240:66;16229:78;;16228:85;16224:305;;16437:66;16344;16333:78;;:171;16329:175;;16224:305;16575:66;16564:78;;16563:85;16559:306;;16772:66;16679;16668:78;;:171;16664:175;;16559:306;16912:66;16901:78;;16900:85;16896:307;;17109:66;17016;17005:78;;:171;17001:175;;16896:307;11466:5743;;;;;:::o;2395:107::-;2451:8;839:66;2475:10;2480:1;2483;2475:4;:10::i;:::-;:20;;;;;;;2395:107;-1:-1:-1;;;2395:107:12:o;3088:437::-;3149:7;3191:1;3179;3172:21;3168:215;;;3209:163;3231:140;3290:48;3356:1;3231:41;:140::i;3209:163::-;3392:8;3403:18;3408:1;3418;3403:4;:18::i;:::-;3392:29;;3440:1;3435;:6;3431:45;;3464:1;3457:8;;;;;3431:45;3514:3;3500:17;;3088:437;-1:-1:-1;;;3088:437:12:o;1023:369:19:-;1352:28;;;:33;;;1023:369::o;408:572:50:-;567:17;;646:7;642:79;;-1:-1:-1;689:2:50;;-1:-1:-1;707:2:50;669:41;;642:79;734:7;730:79;;-1:-1:-1;777:2:50;;-1:-1:-1;795:2:50;757:41;;730:79;830:64;879:14;:2;890;879:14;:10;:14;:::i;:::-;830:27;:2;854;830:27;:23;:27;:::i;:64::-;818:76;-1:-1:-1;918:14:50;:2;929;918:14;:10;:14;:::i;:::-;904:28;-1:-1:-1;408:572:50;;;;;;;;:::o;2687:285::-;2828:23;2865:25;2922:43;2932:9;2943:11;2956:8;2922:9;:43::i;:::-;2915:50;;;;2687:285;;;;;:::o;1674:289:13:-;1805:12;1876:29;1925:5;1919:12;;;;;;;;1945:1;1840:116;;;;;;;;;;17291:398:12;17347:8;17371:6;17367:45;;-1:-1:-1;17400:1:12;17393:8;;17367:45;-1:-1:-1;17425:5:12;;;17429:1;17425;:5;:1;17444:5;;;;;:10;;:24;;;;17467:1;17462;17458;:5;;;;;;:10;;17444:24;17440:243;;;17484:188;17506:165;17557:62;17637:1;17656;17506:33;:165::i;17776:570::-;17832:8;17856:6;17852:218;;17878:181;17900:158;17951:55;18024:1;18043;17900:33;:158::i;17878:181::-;973:66;18083:1;:18;:29;;;;;18105:1;18110:2;18105:7;18083:29;18079:242;;;18128:182;18150:159;18201:56;18275:1;18294;18150:33;:159::i;18128:182::-;18338:1;18334;:5;;;;1384:284:13;1512:12;1583:27;1630:5;1624:12;;;;;;;1435:904:50;1602:23;1639:25;1859:8;1847:9;:20;:46;;;;1885:8;1871:11;:22;1847:46;1843:437;;;1909:19;1944:11;1931:9;:24;;:50;;1970:11;1931:50;;;1958:9;1931:50;1909:72;-1:-1:-1;2009:29:50;1909:72;2029:8;2009:29;:19;:29;:::i;:::-;1995:43;-1:-1:-1;2070:30:50;:9;1995:43;2070:30;:17;:30;:::i;:::-;2052:48;-1:-1:-1;2134:32:50;:11;2154;2134:32;:19;:32;:::i;:::-;2114:52;;1843:437;;;;-1:-1:-1;2215:9:50;;2258:11;;-1:-1:-1;;1435:904:50:o;1969:305:13:-;2109:12;2180:21;2221:5;2215:12;;;;;;;;2241:1;2256;2144:123;;;;;;;;;;;781:550:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;-1:-1:-1;781:550:0;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;-1:-1:-1;781:550:0;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;5:130:-1;72:20;;29279:42;29268:54;;31855:35;;31845:2;;31904:1;;31894:12;746:159;;858:2;849:6;844:3;840:16;836:25;833:2;;;-1:-1;;864:12;1325:241;;1429:2;1417:9;1408:7;1404:23;1400:32;1397:2;;;-1:-1;;1435:12;1397:2;1497:53;1542:7;1518:22;1497:53;;1573:491;;;;1711:2;1699:9;1690:7;1686:23;1682:32;1679:2;;;-1:-1;;1717:12;1679:2;85:6;72:20;97:33;124:5;97:33;;;1769:63;-1:-1;1869:2;1908:22;;72:20;97:33;72:20;97:33;;;1673:391;;1877:63;;-1:-1;;;1977:2;2016:22;;;;979:20;;1673:391;2071:366;;;2192:2;2180:9;2171:7;2167:23;2163:32;2160:2;;;-1:-1;;2198:12;2160:2;2260:53;2305:7;2281:22;2260:53;;;2250:63;2350:2;2389:22;;;;475:20;;-1:-1;;;2154:283;2444:396;;;2580:2;2568:9;2559:7;2555:23;2551:32;2548:2;;;-1:-1;;2586:12;2548:2;2648:53;2693:7;2669:22;2648:53;;;2638:63;;2738:2;2796:9;2792:22;627:20;652:48;694:5;652:48;;;2746:78;;;;2542:298;;;;;;3220:257;;3332:2;3320:9;3311:7;3307:23;3303:32;3300:2;;;-1:-1;;3338:12;3300:2;354:6;348:13;366:30;390:5;366:30;;3484:241;;3588:2;3576:9;3567:7;3563:23;3559:32;3556:2;;;-1:-1;;3594:12;3556:2;-1:-1;475:20;;3550:175;-1:-1;3550:175;3732:366;;;3853:2;3841:9;3832:7;3828:23;3824:32;3821:2;;;-1:-1;;3859:12;3821:2;488:6;475:20;3911:63;;4011:2;4054:9;4050:22;72:20;97:33;124:5;97:33;;4105:366;;;4226:2;4214:9;4205:7;4201:23;4197:32;4194:2;;;-1:-1;;4232:12;4194:2;-1:-1;;475:20;;;4384:2;4423:22;;;979:20;;-1:-1;4188:283;4478:364;;;4598:2;4586:9;4577:7;4573:23;4569:32;4566:2;;;-1:-1;;4604:12;4566:2;488:6;475:20;4656:63;;4756:2;4798:9;4794:22;1256:20;29485:10;32487:5;29474:22;32463:5;32460:34;32450:2;;-1:-1;;32498:12;4849:271;;4968:2;4956:9;4947:7;4943:23;4939:32;4936:2;;;-1:-1;;4974:12;4936:2;640:6;627:20;652:48;694:5;652:48;;5127:605;;;;5321:3;5309:9;5300:7;5296:23;5292:33;5289:2;;;-1:-1;;5328:12;5289:2;5390:81;5463:7;5439:22;5390:81;;;5380:91;;5526:81;5599:7;5508:2;5579:9;5575:22;5526:81;;;5516:91;;5644:3;5688:9;5684:22;979:20;5653:63;;5283:449;;;;;;5987:263;;6102:2;6090:9;6081:7;6077:23;6073:32;6070:2;;;-1:-1;;6108:12;6070:2;-1:-1;1127:13;;6064:186;-1:-1;6064:186;6257:737;;;;;;6426:3;6414:9;6405:7;6401:23;6397:33;6394:2;;;-1:-1;;6433:12;6394:2;992:6;979:20;6485:63;;6585:2;6627:9;6623:22;1256:20;1281:32;1307:5;1281:32;;;6593:62;-1:-1;6692:2;6731:22;;979:20;;-1:-1;6800:2;6838:22;;1256:20;1281:32;1256:20;1281:32;;;6808:62;-1:-1;6907:3;6946:22;;1256:20;1281:32;1256:20;1281:32;;;6916:62;;;;6388:606;;;;;;;;;7001:358;;;7118:2;7106:9;7097:7;7093:23;7089:32;7086:2;;;-1:-1;;7124:12;7086:2;1269:6;1256:20;1281:32;1307:5;1281:32;;;7176:62;-1:-1;7275:2;7311:22;;206:20;231:30;206:20;231:30;;13727:213;29279:42;29268:54;;;;7609:37;;13845:2;13830:18;;13816:124;13947:324;29279:42;29268:54;;;7609:37;;29268:54;;14257:2;14242:18;;7609:37;14093:2;14078:18;;14064:207;14278:435;29279:42;29268:54;;;7609:37;;29268:54;;;;14616:2;14601:18;;7609:37;14699:2;14684:18;;8689:37;;;;14452:2;14437:18;;14423:290;14720:324;29279:42;29268:54;;;;7609:37;;15030:2;15015:18;;8689:37;14866:2;14851:18;;14837:207;15382:361;15550:2;15564:47;;;27686:12;;15535:18;;;27961:19;;;15382:361;;27540:14;;;28001;;;;15382:361;8217:260;8242:6;8239:1;8236:13;8217:260;;;8303:13;;29279:42;29268:54;7609:37;;15550:2;27816:14;;;;7520;;;;8264:1;8257:9;8217:260;;;-1:-1;15617:116;;15521:222;-1:-1;;;;;15521:222;15750:201;28365:13;;28358:21;8572:34;;15862:2;15847:18;;15833:118;15958:213;8689:37;;;16076:2;16061:18;;16047:124;16178:431;8689:37;;;29279:42;29268:54;;;;16514:2;16499:18;;7609:37;29485:10;29474:22;16595:2;16580:18;;13234:36;16350:2;16335:18;;16321:288;16616:312;8689:37;;;28365:13;28358:21;16914:2;16899:18;;8572:34;16756:2;16741:18;;16727:201;16935:324;8689:37;;;17245:2;17230:18;;8689:37;17081:2;17066:18;;17052:207;17780:473;17973:2;17958:18;;31391:1;31381:12;;31371:2;;31397:9;31371:2;9168:69;;;18156:2;18141:18;;8689:37;;;;18239:2;18224:18;;;8689:37;17944:309;;18260:368;18428:2;18413:18;;31513:1;31503:12;;31493:2;;31519:9;31493:2;9342:72;;;18614:2;18599:18;8689:37;18399:229;;18635:380;18809:2;18794:18;;28884:63;28941:5;28884:63;;;9525:78;;;29279:42;29268:54;;;;19001:2;18986:18;;;7609:37;18780:235;;19022:483;19220:2;19205:18;;28884:63;28941:5;28884:63;;;9712:76;;;19410:2;19395:18;;8689:37;;;;29485:10;29474:22;19491:2;19476:18;;;13234:36;19191:314;;19859:407;20050:2;20064:47;;;10291:2;20035:18;;;27961:19;10327:66;28001:14;;;10307:87;10413:12;;;20021:245;20273:407;20464:2;20478:47;;;10664:2;20449:18;;;27961:19;10700:66;28001:14;;;10680:87;10786:12;;;20435:245;20687:317;11093:22;;8689:37;;11271:4;11260:16;;;11254:23;11331:14;;;8689:37;11433:4;11422:16;;;11416:23;11493:14;;;8689:37;;;;20857:2;20842:18;;20828:176;21011:297;11792:22;;29279:42;29268:54;7609:37;;11970:4;11959:16;;;11953:23;29485:10;29474:22;12028:14;;;13234:36;;;;21171:2;21156:18;;21142:166;21315:333;12367:22;;29580:18;29569:30;13458:36;;12549:4;12538:16;;;12532:23;29771:26;29760:38;;;12607:14;;;13679:36;;;;12713:4;12702:16;;;12696:23;29760:38;12771:14;;;13679:36;;;;21493:2;21478:18;;21464:184;22206:435;8689:37;;;22544:2;22529:18;;8689:37;;;;22627:2;22612:18;;8689:37;22380:2;22365:18;;22351:290;22648:547;8689:37;;;23015:2;23000:18;;8689:37;;;;23098:2;23083:18;;8689:37;23181:2;23166:18;;8689:37;22850:3;22835:19;;22821:374;23202:659;8689:37;;;23597:2;23582:18;;8689:37;;;;23680:2;23665:18;;8689:37;;;;23763:2;23748:18;;8689:37;23846:3;23831:19;;8689:37;23432:3;23417:19;;23403:458;23868:651;8689:37;;;29485:10;29474:22;;;24257:2;24242:18;;13234:36;24340:2;24325:18;;8689:37;;;;29474:22;;24422:2;24407:18;;13114:49;29474:22;24504:3;24489:19;;13114:49;24094:3;24079:19;;24065:454;25180:419;8689:37;;;29682:4;29671:16;;;25506:2;25491:18;;13573:35;29671:16;25585:2;25570:18;;13573:35;25346:2;25331:18;;25317:282;25606:209;29485:10;29474:22;;;;13234:36;;25722:2;25707:18;;25693:122;25822:316;29485:10;29474:22;;;13234:36;;29474:22;;26124:2;26109:18;;13234:36;25964:2;25949:18;;25935:203;26145:205;29682:4;29671:16;;;;13573:35;;26259:2;26244:18;;26230:120;26357:312;29682:4;29671:16;;;;13573:35;;26655:2;26640:18;;8689:37;26497:2;26482:18;;26468:201;26676:419;29682:4;29671:16;;;;13573:35;;27000:2;26985:18;;8689:37;;;;27081:2;27066:18;;8689:37;26842:2;26827:18;;26813:282;31542:121;31641:1;31634:5;31631:12;31621:2;;31647:9;31796:117;29279:42;31883:5;29268:54;31858:5;31855:35;31845:2;;31904:1;;31894:12;31920:111;32001:5;28365:13;28358:21;31979:5;31976:32;31966:2;;32022:1;;32012:12;32162:109;32246:1;32239:5;32236:12;32226:2;;32262:1;;32252:12;32402:115;29485:10;32487:5;29474:22;32463:5;32460:34;32450:2;;32508:1;;32498:12

Swarm Source

bzzr://006210cdecfe6b555e273506a51e8f70592803d6dba0c5040fa921b6f79ac217

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  ]

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.