Contract 0x8648adbec6faa9abc5b5f3d188366cbeb8761ceb 2

 
Txn Hash Method
Block
From
To
Value [Txn Fee]
0xe20321ab77defd1f51e4ffdaef1de79908f22034e97e2763233ea33774f4ad1d0x6080604049565552022-01-24 8:49:03307 days 9 hrs ago0xb013abd83f0bd173e9f14ce7d6e420ad711483b4 IN  Create: Crafting0 ETH0.092325726173 ETH
[ Download CSV Export 
Latest 8 internal transactions
Parent Txn Hash Block From To Value
0xbe296d03d1ab5674d50b311bdd82755c96eaee7ad26db94ee84e527ce9ebb89e57606262022-02-10 1:22:03290 days 16 hrs ago 0xe647b2c46365741e85268ced243113d08f7e00b8 0x8648adbec6faa9abc5b5f3d188366cbeb8761ceb0 ETH
0x6fa779e5e85ad41a7613623c4337e75884d81eb1f27462c88bc5c22c0d0c891c57604212022-02-10 1:16:28290 days 16 hrs ago 0xe647b2c46365741e85268ced243113d08f7e00b8 0x8648adbec6faa9abc5b5f3d188366cbeb8761ceb0 ETH
0xda741de722f2e29dee0ae0017a744bdabc621b3a322cb44476b9ef3ec2b1f1cf57602852022-02-10 1:12:57290 days 16 hrs ago 0xe647b2c46365741e85268ced243113d08f7e00b8 0x8648adbec6faa9abc5b5f3d188366cbeb8761ceb0 ETH
0x457728629cfcf41577804c79ca2ab5c87499f7e8be4d9676131f2f4d0178acb557602842022-02-10 1:12:57290 days 16 hrs ago 0xe647b2c46365741e85268ced243113d08f7e00b8 0x8648adbec6faa9abc5b5f3d188366cbeb8761ceb0 ETH
0xeaccd7f5dbd3bed6a61b84173b09e8a8d11466aa5681f63de10b329cb07342d849572182022-01-24 9:14:09307 days 8 hrs ago 0xb013abd83f0bd173e9f14ce7d6e420ad711483b4 0x8648adbec6faa9abc5b5f3d188366cbeb8761ceb0 ETH
0x704b8e087ade3c6b0b4d3189119c265f52ce9654c2922fcff39b5f9289c72aa049572152022-01-24 9:14:09307 days 8 hrs ago 0xb013abd83f0bd173e9f14ce7d6e420ad711483b4 0x8648adbec6faa9abc5b5f3d188366cbeb8761ceb0 ETH
0x24b7e2712b1886c6a41679a0aa74d8436090d2bf024d9553d5f037c3efb046de49567772022-01-24 8:56:02307 days 8 hrs ago 0xb013abd83f0bd173e9f14ce7d6e420ad711483b4 0x8648adbec6faa9abc5b5f3d188366cbeb8761ceb0 ETH
0xb1812405a9631ea008d916394d372fcdab4b21c34f19e1082545d0cc491929ec49565622022-01-24 8:49:03307 days 9 hrs ago 0xb013abd83f0bd173e9f14ce7d6e420ad711483b4 0x8648adbec6faa9abc5b5f3d188366cbeb8761ceb0 ETH
[ Download CSV Export 
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
Crafting

Compiler Version
v0.8.9+commit.e5eed63a

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 33 : Crafting.sol
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

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

import "./CraftingSettings.sol";

contract Crafting is Initializable, CraftingSettings {

    using EnumerableSetUpgradeable for EnumerableSetUpgradeable.UintSet;

    function initialize() external initializer {
        CraftingSettings.__CraftingSettings_init();
    }

    function startCrafting(
        uint256 _tokenId,
        RecipeDifficulty _difficulty,
        uint256[] calldata _treasureIds,
        uint8[] calldata _treasureAmounts)
    external
    whenNotPaused
    contractsAreSet
    onlyEOA
    {
        require(treasury.isBridgeWorldPowered(), "Bridge World not powered");

        LegionMetadata memory _legionMetadata = legionMetadataStore.metadataForLegion(_tokenId);

        require(_legionMetadata.legionGeneration != LegionGeneration.RECRUIT, "Cannot craft with recruit");

        uint8 _levelNeededForDifficulty = difficultyToLevelUnlocked[_difficulty];
        require(_legionMetadata.craftLevel >= _levelNeededForDifficulty, "Difficult not unlocked");

        userToLegionsInProgress[msg.sender].add(_tokenId);

        tokenIdToCraftingStartTime[_tokenId] = block.timestamp;

        uint256 _requestId = randomizer.requestRandomNumber();
        tokenIdToRequestId[_tokenId] = _requestId;

        tokenIdToRecipeDifficulty[_tokenId] = _difficulty;

        _validateAndStoreTreasure(_tokenId, _difficulty, _treasureIds, _treasureAmounts);

        bool _wasMagicTransferred = magic.transferFrom(msg.sender, address(this), craftingFee);
        require(_wasMagicTransferred, "Magic did not transfer");

        tokenIdToMagicPaid[_tokenId] = craftingFee;

        // Transfer the legion to be staked in this contract. This will handle
        // cases when the user doesn't own the tokens
        legion.adminSafeTransferFrom(msg.sender, address(this), _tokenId);

        emit CraftingStarted(msg.sender, _tokenId, _requestId, block.timestamp + difficultyToRecipeLength[_difficulty], _treasureIds, _treasureAmounts);
    }

    function _validateAndStoreTreasure(
        uint256 _tokenId,
        RecipeDifficulty _difficulty,
        uint256[] memory _treasureIds,
        uint8[] memory _treasureAmounts)
    private
    {
        require(_treasureIds.length > 0
            && _treasureIds.length == _treasureAmounts.length, "Bad treasure input");

        uint8[5] memory _amountNeededPerTier = difficultyToAmountPerTier[_difficulty];

        uint8[] memory _amountGivenPerTier = new uint8[](5);

        // Just need to convert to an array of uint256 for the transfer function.
        uint256[] memory _treasureAmounts256 = new uint256[](_treasureAmounts.length);

        for(uint256 i = 0; i < _treasureIds.length; i++) {
            // Will revert if no metadata for the given ID. This can help prevent
            // them supplying garbage.
            TreasureMetadata memory _treasureMetadata = treasureMetadataStore.getMetadataForTreasureId(_treasureIds[i]);

            require(_treasureMetadata.tier >= 1 && _treasureMetadata.tier <= 5, "Bad treasure tier");

            _amountGivenPerTier[_treasureMetadata.tier - 1] += _treasureAmounts[i];

            _treasureAmounts256[i] = _treasureAmounts[i];

            tokenIdToStakedTreasure[_tokenId].push(StakedTreasure(_treasureAmounts[i], _treasureIds[i]));
        }

        for(uint256 i = 0; i < _amountGivenPerTier.length; i++) {
            require(_amountNeededPerTier[i] == _amountGivenPerTier[i], "Incorrect amount for recipe");
        }

        treasure.safeBatchTransferFrom(
            msg.sender,
            address(this),
            _treasureIds,
            _treasureAmounts256, "");
    }

    function revealTokensCraftings(uint256[] calldata _tokenIds)
    external
    contractsAreSet
    whenNotPaused
    nonZeroLength(_tokenIds)
    onlyEOA
    {
        for(uint256 i = 0; i < _tokenIds.length; i++) {
            require(userToLegionsInProgress[msg.sender].contains(_tokenIds[i]), "Not owned by user");

            _revealCrafting(_tokenIds[i]);
        }
    }

    function revealCraftings()
    external
    contractsAreSet
    whenNotPaused
    onlyEOA
    {
        uint256[] memory _tokenIds = userToLegionsInProgress[msg.sender].values();

        for(uint256 i = 0; i < _tokenIds.length; i++) {
            _revealCrafting(_tokenIds[i]);
        }
    }

    function _revealCrafting(uint256 _tokenId) private {
        uint256 _requestId = tokenIdToRequestId[_tokenId];
        if(_requestId == 0) {
            // Already revealed, just in the waiting period.
            return;
        }

        if(!randomizer.isRandomReady(_requestId)) {
            return;
        }

        uint256 _randomNumber = randomizer.revealRandomNumber(_requestId);

        RecipeDifficulty _difficulty = tokenIdToRecipeDifficulty[_tokenId];
        LegionMetadata memory _legionMetadata = legionMetadataStore.metadataForLegion(_tokenId);

        uint256 _successOutcome = _randomNumber % 100000;

        uint256 _magicPaid = tokenIdToMagicPaid[_tokenId];

        bool _wasSuccessful = _successOutcome < difficultyToSuccessRate[_difficulty];
        uint256 _rewardId;
        uint8 _rewardAmount;
        uint256[] memory _brokenTreasureIds;
        uint256[] memory _brokenAmounts;
        uint256 _magicReimbursement;

        if(_wasSuccessful) {
            _randomNumber = uint256(keccak256(abi.encode(_randomNumber, _randomNumber)));

            (_rewardId, _rewardAmount) = _calculateAndDistributeReward(_difficulty, _randomNumber);

            _randomNumber = uint256(keccak256(abi.encode(_randomNumber, _randomNumber)));

            (_brokenTreasureIds, _brokenAmounts) = _calculateBrokenTreasure(_tokenId, _randomNumber);
            _processCPGainAndLevelUp(_tokenId, _legionMetadata.craftLevel);
        } else {
            // Fail
            _magicReimbursement = (_magicPaid * percentReturnedOnFailure) / 100;

            if(_magicReimbursement > 0) {
                bool _wasMagicTransferred = magic.transfer(msg.sender, _magicReimbursement);
                require(_wasMagicTransferred, "Magic failed to be reimbursed");
            }
        }

        // Send rest of magic to the treasury.
        if(_magicPaid > _magicReimbursement && _magicPaid > 0) {
            magic.transfer(address(treasury), _magicPaid - _magicReimbursement);
            treasury.forwardCoinsToMine(_magicPaid - _magicReimbursement);
        }

        delete tokenIdToRequestId[_tokenId];
        delete tokenIdToMagicPaid[_tokenId];

        emit CraftingRevealed(
            msg.sender,
            _tokenId,
            CraftingOutcome(
                _wasSuccessful,
                _magicReimbursement,
                _rewardId,
                _brokenTreasureIds,
                _brokenAmounts,
                _rewardAmount
            ));
    }

    function _calculateAndDistributeReward(
        RecipeDifficulty _difficulty,
        uint256 _randomNumber)
    private
    returns(uint256, uint8)
    {
        CraftingReward[] memory _rewardOptions = difficultyToRewards[_difficulty];
        require(_rewardOptions.length > 0, "No rewards set for difficulty");

        uint256 _rewardResult = _randomNumber % 100000;

        uint256 _topRange = 0;
        for(uint256 i = 0; i < _rewardOptions.length; i++) {
            _topRange += _rewardOptions[i].odds;
            if(_rewardResult < _topRange) {
                consumable.mint(msg.sender, _rewardOptions[i].consumableId, _rewardOptions[i].amount);
                return (_rewardOptions[i].consumableId, _rewardOptions[i].amount);
            }
        }

        revert("Reward odds are incorrect");
    }

    function _calculateBrokenTreasure(
        uint256 _tokenId,
        uint256 _randomNumber)
    private
    returns(uint256[] memory, uint256[] memory) {
        StakedTreasure[] memory _stakedTreasures = tokenIdToStakedTreasure[_tokenId];

        uint256[] memory _brokenTreasureIds = new uint256[](_stakedTreasures.length);
        uint256[] memory _brokenAmounts = new uint256[](_stakedTreasures.length);
        uint256 _brokenIndex = 0;

        for(uint256 i = 0; i < _stakedTreasures.length; i++) {
            StakedTreasure memory _stakedTreasure = _stakedTreasures[i];
            TreasureMetadata memory _treasureMetadata = treasureMetadataStore.getMetadataForTreasureId(_stakedTreasure.treasureId);

            uint256 _treasureAmount = _stakedTreasure.amount;
            for(uint256 j = 0; j < _treasureAmount; j++) {

                uint256 _breakResult = _randomNumber % 100000;
                if(_treasureMetadata.craftingBreakOdds < _breakResult) {
                    _brokenTreasureIds[_brokenIndex] = _stakedTreasure.treasureId;

                    // Remove 1 from amount. If this is reduced to 0,
                    // when the user unstakes the legion, they won't get anything
                    // sent back.
                    tokenIdToStakedTreasure[_tokenId][i].amount--;

                    _brokenAmounts[_brokenIndex]++;

                    if(_treasureMetadata.consumableIdDropWhenBreak > 0) {
                        consumable.mint(msg.sender, _treasureMetadata.consumableIdDropWhenBreak, 1);
                    }
                }

                _randomNumber = uint256(keccak256(abi.encode(_randomNumber, _randomNumber)));
            }
            if(_brokenAmounts[_brokenIndex] > 0) {
                _brokenIndex++;
            }
        }

        // Transfer any broken treasury to the treasury
        if(_brokenIndex > 0) {
            treasure.safeBatchTransferFrom(address(this), address(treasury), _brokenTreasureIds, _brokenAmounts, "");
        }

        return (_brokenTreasureIds, _brokenAmounts);
    }

    function _processCPGainAndLevelUp(uint256 _tokenId, uint8 _currentCraftingLevel) private {
        // No need to do anything if they're at the max level.
        if(_currentCraftingLevel >= maxCraftingLevel) {
            return;
        }

        // Add CP relative to their current level.
        tokenIdToCP[_tokenId] += levelToCPGainedPerRecipe[_currentCraftingLevel];

        // While the user is not max level
        // and they have enough to go to the next level.
        while(_currentCraftingLevel < maxCraftingLevel
            && tokenIdToCP[_tokenId] >= levelToCPNeeded[_currentCraftingLevel])
        {
            tokenIdToCP[_tokenId] -= levelToCPNeeded[_currentCraftingLevel];
            legionMetadataStore.increaseQuestLevel(_tokenId);
            _currentCraftingLevel++;
        }
    }

    function finishTokensCrafting(uint256[] calldata _tokenIds)
    external
    contractsAreSet
    whenNotPaused
    nonZeroLength(_tokenIds)
    onlyEOA
    {
        for(uint256 i = 0; i < _tokenIds.length; i++) {
            require(userToLegionsInProgress[msg.sender].contains(_tokenIds[i]), "Not owned by user");

            _finishCrafting(_tokenIds[i]);
        }
    }

    function finishCrafting()
    external
    contractsAreSet
    whenNotPaused
    onlyEOA
    {
        uint256[] memory _tokenIds = userToLegionsInProgress[msg.sender].values();

        for(uint256 i = 0; i < _tokenIds.length; i++) {
            _finishCrafting(_tokenIds[i]);
        }
    }

    function _finishCrafting(uint256 _tokenId) private {
        uint256 _requestId = tokenIdToRequestId[_tokenId];
        if(_requestId != 0) {
            // Has not revealed rewards yet!!
            return;
        }

        RecipeDifficulty _difficulty = tokenIdToRecipeDifficulty[_tokenId];

        // Check if crafting cooldown is done.
        if(block.timestamp < tokenIdToCraftingStartTime[_tokenId] + difficultyToRecipeLength[_difficulty]) {
            return;
        }

        StakedTreasure[] memory _stakedTreasures = tokenIdToStakedTreasure[_tokenId];

        uint256[] memory _treasureIds = new uint256[](_stakedTreasures.length);
        uint256[] memory _treasureAmounts = new uint256[](_stakedTreasures.length);
        uint256 _treasureIndex;

        for(uint256 i = 0; i < _stakedTreasures.length; i++) {
            StakedTreasure memory _stakedTreasure = _stakedTreasures[i];

            if(_stakedTreasure.treasureId > 0 && _stakedTreasure.amount > 0) {
                _treasureIds[_treasureIndex] = _stakedTreasure.treasureId;
                _treasureAmounts[_treasureIndex] = _stakedTreasure.amount;
                _treasureIndex++;
            }
        }

        if(_treasureIndex > 0) {
            treasure.safeBatchTransferFrom(address(this), msg.sender, _treasureIds, _treasureAmounts, "");
        }

        userToLegionsInProgress[msg.sender].remove(_tokenId);
        delete tokenIdToStakedTreasure[_tokenId];
        delete tokenIdToRecipeDifficulty[_tokenId];
        delete tokenIdToCraftingStartTime[_tokenId];

        legion.adminSafeTransferFrom(address(this), msg.sender, _tokenId);

        emit CraftingFinished(msg.sender, _tokenId);
    }
}

File 2 of 33 : Initializable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (proxy/utils/Initializable.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

        _;

        if (isTopLevelCall) {
            _initializing = false;
        }
    }

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

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

File 3 of 33 : CraftingSettings.sol
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

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

import "./CraftingContracts.sol";

abstract contract CraftingSettings is Initializable, CraftingContracts {

    using EnumerableSetUpgradeable for EnumerableSetUpgradeable.UintSet;

    function __CraftingSettings_init() internal initializer {
        CraftingContracts.__CraftingContracts_init();
    }

    function setSimpleSettings(
        uint256 _craftingFee,
        uint8 _percentReturnedOnFailure)
    external
    onlyAdminOrOwner
    {
        require(_percentReturnedOnFailure >= 0 && _percentReturnedOnFailure <= 100, "Bad refund percent");
        craftingFee = _craftingFee;
        percentReturnedOnFailure = _percentReturnedOnFailure;
    }

    function setRewards(
        CraftingReward[] calldata _easyRewards,
        CraftingReward[] calldata _mediumRewards,
        CraftingReward[] calldata _hardRewards)
    external
    onlyAdminOrOwner
    {

        RecipeDifficulty[3] memory _difficulties = [
            RecipeDifficulty.EASY,
            RecipeDifficulty.MEDIUM,
            RecipeDifficulty.HARD
        ];

        for(uint256 i = 0; i < _difficulties.length; i++) {
            delete difficultyToRewards[_difficulties[i]];

            CraftingReward[] memory _rewardsForDifficulty;
            if(_difficulties[i] == RecipeDifficulty.EASY) {
                _rewardsForDifficulty = _easyRewards;
            } else if(_difficulties[i] == RecipeDifficulty.MEDIUM) {
                _rewardsForDifficulty = _mediumRewards;
            } else {
                _rewardsForDifficulty = _hardRewards;
            }
            uint256 _totalRewardOdds = 0;
            for(uint256 j = 0; j < _rewardsForDifficulty.length; j++) {
                difficultyToRewards[_difficulties[i]].push(_rewardsForDifficulty[j]);
                _totalRewardOdds += _rewardsForDifficulty[j].odds;
            }

            require(_totalRewardOdds == 100000, "Bad odds");
        }
    }

    function setDifficultySettings(
        uint256[3] calldata _recipeLengths,
        uint256[3] calldata _successRates,
        uint8[5][3] calldata _treasureAmountPerTier,
        uint8[3] memory _levelUnlocked)
    external
    onlyAdminOrOwner
    {
        difficultyToRecipeLength[RecipeDifficulty.EASY] = _recipeLengths[0];
        difficultyToRecipeLength[RecipeDifficulty.MEDIUM] = _recipeLengths[1];
        difficultyToRecipeLength[RecipeDifficulty.HARD] = _recipeLengths[2];

        difficultyToSuccessRate[RecipeDifficulty.EASY] = _successRates[0];
        difficultyToSuccessRate[RecipeDifficulty.MEDIUM] = _successRates[1];
        difficultyToSuccessRate[RecipeDifficulty.HARD] = _successRates[2];

        for(uint256 i = 0; i < 5; i++) {
            difficultyToAmountPerTier[RecipeDifficulty.EASY][i] = _treasureAmountPerTier[0][i];
            difficultyToAmountPerTier[RecipeDifficulty.MEDIUM][i] = _treasureAmountPerTier[1][i];
            difficultyToAmountPerTier[RecipeDifficulty.HARD][i] = _treasureAmountPerTier[2][i];
        }

        difficultyToLevelUnlocked[RecipeDifficulty.EASY] = _levelUnlocked[0];
        difficultyToLevelUnlocked[RecipeDifficulty.MEDIUM] = _levelUnlocked[1];
        difficultyToLevelUnlocked[RecipeDifficulty.HARD] = _levelUnlocked[2];
    }

    function setCraftingLevelSettings(
        uint8 _maxCraftingLevel,
        uint256[] calldata _levelToCPNeeded,
        uint256[] calldata _levelToCPGainedPerRecipe)
    external
    onlyAdminOrOwner
    {
        require(_maxCraftingLevel > 0, "Bad max level");
        require(_levelToCPNeeded.length == _maxCraftingLevel - 1, "Not enough CP steps");
        require(_levelToCPGainedPerRecipe.length == _maxCraftingLevel - 1, "Not enough CP gained steps");

        maxCraftingLevel = _maxCraftingLevel;

        delete levelToCPNeeded;
        delete levelToCPGainedPerRecipe;

        levelToCPNeeded.push(0);
        levelToCPGainedPerRecipe.push(0);

        for(uint256 i = 0; i < _maxCraftingLevel - 1; i++) {
            levelToCPNeeded.push(_levelToCPNeeded[i]);
            levelToCPGainedPerRecipe.push(_levelToCPGainedPerRecipe[i]);
        }
    }
}

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

pragma solidity ^0.8.0;

/**
 * @dev Collection of functions related to the address type
 */
library AddressUpgradeable {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize, which returns 0 for contracts in
        // construction, since the code is only stored at the end of the
        // constructor execution.

        uint256 size;
        assembly {
            size := extcodesize(account)
        }
        return size > 0;
    }

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

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

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

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

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

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

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

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

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

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

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

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

File 5 of 33 : CraftingContracts.sol
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

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

import "./CraftingState.sol";

abstract contract CraftingContracts is Initializable, CraftingState {

    function __CraftingContracts_init() internal initializer {
        CraftingState.__CraftingState_init();
    }

    function setContracts(
        address _randomizerAddress,
        address _treasureAddress,
        address _legionAddress,
        address _treasureMetadataStoreAddress,
        address _legionMetadataStoreAddress,
        address _magicAddress,
        address _treasuryAddress,
        address _consumableAddress)
    external onlyAdminOrOwner
    {
        randomizer = IRandomizer(_randomizerAddress);
        treasure = ITreasure(_treasureAddress);
        legion = ILegion(_legionAddress);
        treasureMetadataStore = ITreasureMetadataStore(_treasureMetadataStoreAddress);
        legionMetadataStore = ILegionMetadataStore(_legionMetadataStoreAddress);
        magic = IMagic(_magicAddress);
        treasury = ITreasury(_treasuryAddress);
        consumable = IConsumable(_consumableAddress);
    }

    modifier contractsAreSet() {
        require(address(randomizer) != address(0)
            && address(treasure) != address(0)
            && address(legion) != address(0)
            && address(treasureMetadataStore) != address(0)
            && address(legionMetadataStore) != address(0)
            && address(treasury) != address(0)
            && address(consumable) != address(0)
            && address(magic) != address(0), "Contracts aren't set");

        _;
    }
}

File 6 of 33 : CraftingState.sol
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/utils/structs/EnumerableSetUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC721/utils/ERC721HolderUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC1155/utils/ERC1155HolderUpgradeable.sol";

import "../../shared/randomizer/IRandomizer.sol";
import "./ICrafting.sol";
import "../../shared/AdminableUpgradeable.sol";
import "../external/ITreasure.sol";
import "../external/IMagic.sol";
import "../legion/ILegion.sol";
import "../treasury/ITreasury.sol";
import "../consumable/IConsumable.sol";
import "../treasuremetadatastore/ITreasureMetadataStore.sol";
import "../legionmetadatastore/ILegionMetadataStore.sol";

abstract contract CraftingState is Initializable, ICrafting, ERC721HolderUpgradeable, ERC1155HolderUpgradeable, AdminableUpgradeable {

    using EnumerableSetUpgradeable for EnumerableSetUpgradeable.UintSet;

    event CraftingStarted(address indexed _owner, uint256 indexed _tokenId, uint256 indexed _requestId, uint256 _finishTime, uint256[] _treasureIds, uint8[] _treasureAmounts);
    event CraftingRevealed(address indexed _owner, uint256 indexed _tokenId, CraftingOutcome _outcome);
    event CraftingFinished(address indexed _owner, uint256 indexed _tokenId);

    IRandomizer public randomizer;
    ITreasure public treasure;
    ILegion public legion;
    ITreasureMetadataStore public treasureMetadataStore;
    ILegionMetadataStore public legionMetadataStore;
    IMagic public magic;
    ITreasury public treasury;
    IConsumable public consumable;

    mapping(RecipeDifficulty => uint256) public difficultyToRecipeLength;
    mapping(RecipeDifficulty => uint256) public difficultyToSuccessRate;
    mapping(RecipeDifficulty => uint8[5]) public difficultyToAmountPerTier;
    mapping(RecipeDifficulty => uint8) public difficultyToLevelUnlocked;

    // Reward state
    mapping(RecipeDifficulty => CraftingReward[]) public difficultyToRewards;

    uint8 public maxCraftingLevel;
    uint256[] public levelToCPNeeded;
    uint256[] public levelToCPGainedPerRecipe;

    mapping(address => EnumerableSetUpgradeable.UintSet) internal userToLegionsInProgress;

    mapping(uint256 => uint256) public tokenIdToCP;
    mapping(uint256 => uint256) public tokenIdToCraftingStartTime;
    mapping(uint256 => uint256) public tokenIdToRequestId;
    mapping(uint256 => uint256) public tokenIdToMagicPaid;
    mapping(uint256 => RecipeDifficulty) public tokenIdToRecipeDifficulty;
    mapping(uint256 => StakedTreasure[]) public tokenIdToStakedTreasure;

    uint256 public craftingFee;
    uint8 public percentReturnedOnFailure;

    function __CraftingState_init() internal initializer {
        AdminableUpgradeable.__Adminable_init();
        ERC721HolderUpgradeable.__ERC721Holder_init();
        ERC1155HolderUpgradeable.__ERC1155Holder_init();

        difficultyToRecipeLength[RecipeDifficulty.EASY] = 8 hours;
        difficultyToRecipeLength[RecipeDifficulty.MEDIUM] = 12 hours;
        difficultyToRecipeLength[RecipeDifficulty.HARD] = 16 hours;

        difficultyToSuccessRate[RecipeDifficulty.EASY] = 90000;
        difficultyToSuccessRate[RecipeDifficulty.MEDIUM] = 90000;
        difficultyToSuccessRate[RecipeDifficulty.HARD] = 90000;

        difficultyToLevelUnlocked[RecipeDifficulty.EASY] = 1;
        difficultyToLevelUnlocked[RecipeDifficulty.MEDIUM] = 3;
        difficultyToLevelUnlocked[RecipeDifficulty.HARD] = 5;

        difficultyToAmountPerTier[RecipeDifficulty.EASY] = [0, 0, 0, 1, 2];
        difficultyToAmountPerTier[RecipeDifficulty.MEDIUM] = [0, 0, 1, 2, 2];
        difficultyToAmountPerTier[RecipeDifficulty.HARD] = [1, 1, 1, 2, 2];

        maxCraftingLevel = 6;

        levelToCPNeeded.push(0);
        levelToCPNeeded.push(100);
        levelToCPNeeded.push(200);
        levelToCPNeeded.push(400);
        levelToCPNeeded.push(1500);
        levelToCPNeeded.push(2000);

        levelToCPGainedPerRecipe.push(0);
        levelToCPGainedPerRecipe.push(10);
        levelToCPGainedPerRecipe.push(20);
        levelToCPGainedPerRecipe.push(30);
        levelToCPGainedPerRecipe.push(40);
        levelToCPGainedPerRecipe.push(50);

        percentReturnedOnFailure = 90;

        craftingFee = 25 ether;
    }
}

// Do not change, stored in state.
struct CraftingReward {
    uint256 consumableId;
    uint8 amount;
    uint32 odds;
}

// Do not change, stored in state.
struct StakedTreasure {
    uint8 amount;
    uint256 treasureId;
}

// Safe to change, as only in event not in state.
struct CraftingOutcome {
    bool wasSuccessful;
    uint256 magicReturned;
    uint256 rewardId;
    uint256[] brokenTreasureIds;
    uint256[] brokenAmounts;
    uint8 rewardAmount;
}

enum RecipeDifficulty {
    EASY,
    MEDIUM,
    HARD
}

File 7 of 33 : EnumerableSetUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/structs/EnumerableSet.sol)

pragma solidity ^0.8.0;

/**
 * @dev Library for managing
 * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
 * types.
 *
 * Sets have the following properties:
 *
 * - Elements are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Elements are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```
 * contract Example {
 *     // Add the library methods
 *     using EnumerableSet for EnumerableSet.AddressSet;
 *
 *     // Declare a set state variable
 *     EnumerableSet.AddressSet private mySet;
 * }
 * ```
 *
 * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
 * and `uint256` (`UintSet`) are supported.
 */
library EnumerableSetUpgradeable {
    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Set type with
    // bytes32 values.
    // The Set implementation uses private functions, and user-facing
    // implementations (such as AddressSet) are just wrappers around the
    // underlying Set.
    // This means that we can only create new EnumerableSets for types that fit
    // in bytes32.

    struct Set {
        // Storage of set values
        bytes32[] _values;
        // Position of the value in the `values` array, plus 1 because index 0
        // means a value is not in the set.
        mapping(bytes32 => uint256) _indexes;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function _add(Set storage set, bytes32 value) private returns (bool) {
        if (!_contains(set, value)) {
            set._values.push(value);
            // The value is stored at length-1, but we add 1 to all indexes
            // and use 0 as a sentinel value
            set._indexes[value] = set._values.length;
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function _remove(Set storage set, bytes32 value) private returns (bool) {
        // We read and store the value's index to prevent multiple reads from the same storage slot
        uint256 valueIndex = set._indexes[value];

        if (valueIndex != 0) {
            // Equivalent to contains(set, value)
            // To delete an element from the _values array in O(1), we swap the element to delete with the last one in
            // the array, and then remove the last element (sometimes called as 'swap and pop').
            // This modifies the order of the array, as noted in {at}.

            uint256 toDeleteIndex = valueIndex - 1;
            uint256 lastIndex = set._values.length - 1;

            if (lastIndex != toDeleteIndex) {
                bytes32 lastvalue = set._values[lastIndex];

                // Move the last value to the index where the value to delete is
                set._values[toDeleteIndex] = lastvalue;
                // Update the index for the moved value
                set._indexes[lastvalue] = valueIndex; // Replace lastvalue's index to valueIndex
            }

            // Delete the slot where the moved value was stored
            set._values.pop();

            // Delete the index for the deleted slot
            delete set._indexes[value];

            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function _contains(Set storage set, bytes32 value) private view returns (bool) {
        return set._indexes[value] != 0;
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function _length(Set storage set) private view returns (uint256) {
        return set._values.length;
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function _at(Set storage set, uint256 index) private view returns (bytes32) {
        return set._values[index];
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function _values(Set storage set) private view returns (bytes32[] memory) {
        return set._values;
    }

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _add(set._inner, value);
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _remove(set._inner, value);
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
        return _contains(set._inner, value);
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(Bytes32Set storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
        return _at(set._inner, index);
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
        return _values(set._inner);
    }

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(AddressSet storage set, address value) internal returns (bool) {
        return _add(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(AddressSet storage set, address value) internal returns (bool) {
        return _remove(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(AddressSet storage set, address value) internal view returns (bool) {
        return _contains(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(AddressSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(AddressSet storage set, uint256 index) internal view returns (address) {
        return address(uint160(uint256(_at(set._inner, index))));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(AddressSet storage set) internal view returns (address[] memory) {
        bytes32[] memory store = _values(set._inner);
        address[] memory result;

        assembly {
            result := store
        }

        return result;
    }

    // UintSet

    struct UintSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(UintSet storage set, uint256 value) internal returns (bool) {
        return _add(set._inner, bytes32(value));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(UintSet storage set, uint256 value) internal returns (bool) {
        return _remove(set._inner, bytes32(value));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(UintSet storage set, uint256 value) internal view returns (bool) {
        return _contains(set._inner, bytes32(value));
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function length(UintSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(UintSet storage set, uint256 index) internal view returns (uint256) {
        return uint256(_at(set._inner, index));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(UintSet storage set) internal view returns (uint256[] memory) {
        bytes32[] memory store = _values(set._inner);
        uint256[] memory result;

        assembly {
            result := store
        }

        return result;
    }
}

File 8 of 33 : ERC721HolderUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/utils/ERC721Holder.sol)

pragma solidity ^0.8.0;

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

/**
 * @dev Implementation of the {IERC721Receiver} interface.
 *
 * Accepts all token transfers.
 * Make sure the contract is able to use its token with {IERC721-safeTransferFrom}, {IERC721-approve} or {IERC721-setApprovalForAll}.
 */
contract ERC721HolderUpgradeable is Initializable, IERC721ReceiverUpgradeable {
    function __ERC721Holder_init() internal onlyInitializing {
        __ERC721Holder_init_unchained();
    }

    function __ERC721Holder_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev See {IERC721Receiver-onERC721Received}.
     *
     * Always returns `IERC721Receiver.onERC721Received.selector`.
     */
    function onERC721Received(
        address,
        address,
        uint256,
        bytes memory
    ) public virtual override returns (bytes4) {
        return this.onERC721Received.selector;
    }
    uint256[50] private __gap;
}

File 9 of 33 : ERC1155HolderUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC1155/utils/ERC1155Holder.sol)

pragma solidity ^0.8.0;

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

/**
 * @dev _Available since v3.1._
 */
contract ERC1155HolderUpgradeable is Initializable, ERC1155ReceiverUpgradeable {
    function __ERC1155Holder_init() internal onlyInitializing {
        __ERC165_init_unchained();
        __ERC1155Receiver_init_unchained();
        __ERC1155Holder_init_unchained();
    }

    function __ERC1155Holder_init_unchained() internal onlyInitializing {
    }
    function onERC1155Received(
        address,
        address,
        uint256,
        uint256,
        bytes memory
    ) public virtual override returns (bytes4) {
        return this.onERC1155Received.selector;
    }

    function onERC1155BatchReceived(
        address,
        address,
        uint256[] memory,
        uint256[] memory,
        bytes memory
    ) public virtual override returns (bytes4) {
        return this.onERC1155BatchReceived.selector;
    }
    uint256[50] private __gap;
}

File 10 of 33 : IRandomizer.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface IRandomizer {

    // Sets the number of blocks that must pass between increment the commitId and seeding the random
    // Admin
    function setNumBlocksAfterIncrement(uint8 _numBlocksAfterIncrement) external;

    // Increments the commit id.
    // Admin
    function incrementCommitId() external;

    // Adding the random number needs to be done AFTER incrementing the commit id on a separate transaction. If
    // these are done together, there is a potential vulnerability to front load a commit when the bad actor
    // sees the value of the random number.
    function addRandomForCommit(uint256 _seed) external;

    // Returns a request ID for a random number. This is unique.
    function requestRandomNumber() external returns(uint256);

    // Returns the random number for the given request ID. Will revert
    // if the random is not ready.
    function revealRandomNumber(uint256 _requestId) external view returns(uint256);

    // Returns if the random number for the given request ID is ready or not. Call
    // before calling revealRandomNumber.
    function isRandomReady(uint256 _requestId) external view returns(bool);
}

File 11 of 33 : ICrafting.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface ICrafting {

}

File 12 of 33 : AdminableUpgradeable.sol
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

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

import "./UtilitiesUpgradeable.sol";

// Do not add state to this contract.
//
contract AdminableUpgradeable is UtilitiesUpgradeable {

    mapping(address => bool) private admins;

    function __Adminable_init() internal initializer {
        UtilitiesUpgradeable.__Utilities__init();
    }

    function addAdmin(address _address) external onlyOwner {
        admins[_address] = true;
    }

    function addAdmins(address[] calldata _addresses) external onlyOwner {
        for(uint256 i = 0; i < _addresses.length; i++) {
            admins[_addresses[i]] = true;
        }
    }

    function removeAdmin(address _address) external onlyOwner {
        admins[_address] = false;
    }

    function removeAdmins(address[] calldata _addresses) external onlyOwner {
        for(uint256 i = 0; i < _addresses.length; i++) {
            admins[_addresses[i]] = false;
        }
    }

    function setPause(bool _shouldPause) external onlyAdminOrOwner {
        if(_shouldPause) {
            _pause();
        } else {
            _unpause();
        }
    }

    function isAdmin(address _address) public view returns(bool) {
        return admins[_address];
    }

    modifier onlyAdmin() {
        require(admins[msg.sender], "Not admin");
        _;
    }

    modifier onlyAdminOrOwner() {
        require(admins[msg.sender] || isOwner(), "Not admin or owner");
        _;
    }

    uint256[50] private __gap;
}

File 13 of 33 : ITreasure.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface ITreasure {
    // Transfers the treasure at the given ID of the given amount.
    // Requires that the legions are pre-approved.
    //
    function safeBatchTransferFrom(address _from, address _to, uint256[] calldata _ids, uint256[] calldata _amounts, bytes memory data) external;

    // Transfers the treasure at the given ID of the given amount.
    //
    function safeTransferFrom(address _from, address _to, uint256 _id, uint256 _amount, bytes memory data) external;

    // Admin only.
    //
    function mint(address _account, uint256 _tokenId, uint256 _amount) external;
}

File 14 of 33 : IMagic.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface IMagic {

    // Transfers the given amount to the recipient's wallet. Returns a boolean indicating if it was
    // successful or not.
    function transferFrom(address _sender, address _recipient, uint256 _amount) external returns(bool);

    // Transfer the given amount to the recipient's wallet. The sender is the caller of this function.
    // Returns a boolean indicating if it was successful or not.
    function transfer(address _recipient, uint256 _amount) external returns(bool);

    function approve(address _spender, uint256 _amount) external returns(bool);
}

File 15 of 33 : ILegion.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/IERC721MetadataUpgradeable.sol";

interface ILegion is IERC721MetadataUpgradeable {

    // Mints a legion to the given address. Returns the token ID.
    // Admin only.
    function safeMint(address _to) external returns(uint256);

    // Sets the URI for the given token id. Token must exist.
    // Admin only.
    function setTokenURI(uint256 _tokenId, string calldata _tokenURI) external;

    // Transfers the token to the given address. Does not need approval. _from still must be the owner of the token.
    // Admin only.
    function adminSafeTransferFrom(address _from, address _to, uint256 _tokenId) external;
}

File 16 of 33 : ITreasury.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface ITreasury {

    function isBridgeWorldPowered() external view returns(bool);

    function forwardCoinsToMine(uint256 _totalMagicSent) external;
}

File 17 of 33 : IConsumable.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts-upgradeable/token/ERC1155/IERC1155Upgradeable.sol";

interface IConsumable is IERC1155Upgradeable {

    function mint(address _to, uint256 _id, uint256 _amount) external;

    function burn(address account, uint256 id, uint256 value) external;

    function burnBatch(address account, uint256[] memory ids, uint256[] memory values) external;

    function adminSafeTransferFrom(address _from, address _to, uint256 _id, uint256 _amount) external;

    function adminSafeBatchTransferFrom(address _from, address _to, uint256[] calldata _ids, uint256[] calldata _amounts) external;
}

File 18 of 33 : ITreasureMetadataStore.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "./TreasureMetadataStoreState.sol";

interface ITreasureMetadataStore {
    // Sets the metadata for the given Ids.
    // Admin only.
    function setMetadataForIds(uint256[] calldata _ids, TreasureMetadata[] calldata _metadatas) external;

    // Returns if the given ID has metadata set.
    function hasMetadataForTreasureId(uint256 _treasureId) external view returns(bool);

    // Returns the metadata for the given ID. Reverts if no metadata for the ID is set.
    function getMetadataForTreasureId(uint256 _treasureId) external view returns(TreasureMetadata memory);

    // For the given tier, gets a random MINTABLE treasure id.
    function getRandomTreasureForTier(uint8 _tier, uint256 _randomNumber) external view returns(uint256);
}

// Do not change. Stored in state.
struct TreasureMetadata {
    TreasureCategory category;
    uint8 tier;
    // Out of 100,000
    uint32 craftingBreakOdds;
    bool isMintable;
    uint256 consumableIdDropWhenBreak;
}

enum TreasureCategory {
    ALCHEMY,
    ARCANA,
    BREWING,
    ENCHANTER,
    LEATHERWORKING,
    SMITHING
}

File 19 of 33 : ILegionMetadataStore.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "./LegionMetadataStoreState.sol";

interface ILegionMetadataStore {
    // Sets the intial metadata for a token id.
    // Admin only.
    function setInitialMetadataForLegion(address _owner, uint256 _tokenId, LegionGeneration _generation, LegionClass _class, LegionRarity _rarity, uint256 _oldId) external;

    // Increases the quest level by one. It is up to the calling contract to regulate the max quest level. No validation.
    // Admin only.
    function increaseQuestLevel(uint256 _tokenId) external;

    // Increases the craft level by one. It is up to the calling contract to regulate the max craft level. No validation.
    // Admin only.
    function increaseCraftLevel(uint256 _tokenId) external;

    // Increases the rank of the given constellation to the given number. It is up to the calling contract to regulate the max constellation rank. No validation.
    // Admin only.
    function increaseConstellationRank(uint256 _tokenId, Constellation _constellation, uint8 _to) external;

    // Returns the metadata for the given legion.
    function metadataForLegion(uint256 _tokenId) external view returns(LegionMetadata memory);

    // Returns the tokenUri for the given token.
    function tokenURI(uint256 _tokenId) external view returns(string memory);
}

// As this will likely change in the future, this should not be used to store state, but rather
// as parameters and return values from functions.
struct LegionMetadata {
    LegionGeneration legionGeneration;
    LegionClass legionClass;
    LegionRarity legionRarity;
    uint8 questLevel;
    uint8 craftLevel;
    uint8[6] constellationRanks;
    uint256 oldId;
}

enum Constellation {
    FIRE,
    EARTH,
    WIND,
    WATER,
    LIGHT,
    DARK
}

enum LegionRarity {
    LEGENDARY,
    RARE,
    SPECIAL,
    UNCOMMON,
    COMMON,
    RECRUIT
}

enum LegionClass {
    RECRUIT,
    SIEGE,
    FIGHTER,
    ASSASSIN,
    RANGED,
    SPELLCASTER,
    RIVERMAN,
    NUMERAIRE,
    ALL_CLASS,
    ORIGIN
}

enum LegionGeneration {
    GENESIS,
    AUXILIARY,
    RECRUIT
}

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

pragma solidity ^0.8.0;

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

File 21 of 33 : ERC1155ReceiverUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC1155/utils/ERC1155Receiver.sol)

pragma solidity ^0.8.0;

import "../IERC1155ReceiverUpgradeable.sol";
import "../../../utils/introspection/ERC165Upgradeable.sol";
import "../../../proxy/utils/Initializable.sol";

/**
 * @dev _Available since v3.1._
 */
abstract contract ERC1155ReceiverUpgradeable is Initializable, ERC165Upgradeable, IERC1155ReceiverUpgradeable {
    function __ERC1155Receiver_init() internal onlyInitializing {
        __ERC165_init_unchained();
        __ERC1155Receiver_init_unchained();
    }

    function __ERC1155Receiver_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165Upgradeable, IERC165Upgradeable) returns (bool) {
        return interfaceId == type(IERC1155ReceiverUpgradeable).interfaceId || super.supportsInterface(interfaceId);
    }
    uint256[50] private __gap;
}

File 22 of 33 : IERC1155ReceiverUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC1155/IERC1155Receiver.sol)

pragma solidity ^0.8.0;

import "../../utils/introspection/IERC165Upgradeable.sol";

/**
 * @dev _Available since v3.1._
 */
interface IERC1155ReceiverUpgradeable is IERC165Upgradeable {
    /**
        @dev Handles the receipt of a single ERC1155 token type. This function is
        called at the end of a `safeTransferFrom` after the balance has been updated.
        To accept the transfer, this must return
        `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
        (i.e. 0xf23a6e61, or its own function selector).
        @param operator The address which initiated the transfer (i.e. msg.sender)
        @param from The address which previously owned the token
        @param id The ID of the token being transferred
        @param value The amount of tokens being transferred
        @param data Additional data with no specified format
        @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
    */
    function onERC1155Received(
        address operator,
        address from,
        uint256 id,
        uint256 value,
        bytes calldata data
    ) external returns (bytes4);

    /**
        @dev Handles the receipt of a multiple ERC1155 token types. This function
        is called at the end of a `safeBatchTransferFrom` after the balances have
        been updated. To accept the transfer(s), this must return
        `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
        (i.e. 0xbc197c81, or its own function selector).
        @param operator The address which initiated the batch transfer (i.e. msg.sender)
        @param from The address which previously owned the token
        @param ids An array containing ids of each token being transferred (order and length must match values array)
        @param values An array containing amounts of each token being transferred (order and length must match ids array)
        @param data Additional data with no specified format
        @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
    */
    function onERC1155BatchReceived(
        address operator,
        address from,
        uint256[] calldata ids,
        uint256[] calldata values,
        bytes calldata data
    ) external returns (bytes4);
}

File 23 of 33 : ERC165Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)

pragma solidity ^0.8.0;

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

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 *
 * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
 */
abstract contract ERC165Upgradeable is Initializable, IERC165Upgradeable {
    function __ERC165_init() internal onlyInitializing {
        __ERC165_init_unchained();
    }

    function __ERC165_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IERC165Upgradeable).interfaceId;
    }
    uint256[50] private __gap;
}

File 24 of 33 : IERC165Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)

pragma solidity ^0.8.0;

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

File 25 of 33 : UtilitiesUpgradeable.sol
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

contract UtilitiesUpgradeable is Initializable, OwnableUpgradeable, PausableUpgradeable {

    function __Utilities__init() internal initializer {
        OwnableUpgradeable.__Ownable_init();
        PausableUpgradeable.__Pausable_init();

        _pause();
    }

    modifier nonZeroAddress(address _address) {
        require(address(0) != _address, "0 address");
        _;
    }

    modifier nonZeroLength(uint[] memory _array) {
        require(_array.length > 0, "Empty array");
        _;
    }

    modifier lengthsAreEqual(uint[] memory _array1, uint[] memory _array2) {
        require(_array1.length == _array2.length, "Unequal lengths");
        _;
    }

    modifier onlyEOA() {
        /* solhint-disable avoid-tx-origin */
        require(msg.sender == tx.origin, "No contracts");
        _;
    }

    function isOwner() internal view returns(bool) {
        return owner() == msg.sender;
    }
}

File 26 of 33 : OwnableUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

File 27 of 33 : PausableUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (security/Pausable.sol)

pragma solidity ^0.8.0;

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

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

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

    bool private _paused;

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

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

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

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

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

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

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

File 28 of 33 : ContextUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

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

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

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

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
    uint256[50] private __gap;
}

File 29 of 33 : IERC721MetadataUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol)

pragma solidity ^0.8.0;

import "../IERC721Upgradeable.sol";

/**
 * @title ERC-721 Non-Fungible Token Standard, optional metadata extension
 * @dev See https://eips.ethereum.org/EIPS/eip-721
 */
interface IERC721MetadataUpgradeable is IERC721Upgradeable {
    /**
     * @dev Returns the token collection name.
     */
    function name() external view returns (string memory);

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

    /**
     * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
     */
    function tokenURI(uint256 tokenId) external view returns (string memory);
}

File 30 of 33 : IERC721Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721.sol)

pragma solidity ^0.8.0;

import "../../utils/introspection/IERC165Upgradeable.sol";

/**
 * @dev Required interface of an ERC721 compliant contract.
 */
interface IERC721Upgradeable is IERC165Upgradeable {
    /**
     * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
     */
    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);

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

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

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

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

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

    /**
     * @dev Transfers `tokenId` token from `from` to `to`.
     *
     * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address from,
        address to,
        uint256 tokenId
    ) external;

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

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

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

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

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

File 31 of 33 : IERC1155Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC1155/IERC1155.sol)

pragma solidity ^0.8.0;

import "../../utils/introspection/IERC165Upgradeable.sol";

/**
 * @dev Required interface of an ERC1155 compliant contract, as defined in the
 * https://eips.ethereum.org/EIPS/eip-1155[EIP].
 *
 * _Available since v3.1._
 */
interface IERC1155Upgradeable is IERC165Upgradeable {
    /**
     * @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`.
     */
    event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);

    /**
     * @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all
     * transfers.
     */
    event TransferBatch(
        address indexed operator,
        address indexed from,
        address indexed to,
        uint256[] ids,
        uint256[] values
    );

    /**
     * @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to
     * `approved`.
     */
    event ApprovalForAll(address indexed account, address indexed operator, bool approved);

    /**
     * @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.
     *
     * If an {URI} event was emitted for `id`, the standard
     * https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value
     * returned by {IERC1155MetadataURI-uri}.
     */
    event URI(string value, uint256 indexed id);

    /**
     * @dev Returns the amount of tokens of token type `id` owned by `account`.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     */
    function balanceOf(address account, uint256 id) external view returns (uint256);

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.
     *
     * Requirements:
     *
     * - `accounts` and `ids` must have the same length.
     */
    function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids)
        external
        view
        returns (uint256[] memory);

    /**
     * @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,
     *
     * Emits an {ApprovalForAll} event.
     *
     * Requirements:
     *
     * - `operator` cannot be the caller.
     */
    function setApprovalForAll(address operator, bool approved) external;

    /**
     * @dev Returns true if `operator` is approved to transfer ``account``'s tokens.
     *
     * See {setApprovalForAll}.
     */
    function isApprovedForAll(address account, address operator) external view returns (bool);

    /**
     * @dev Transfers `amount` tokens of token type `id` from `from` to `to`.
     *
     * Emits a {TransferSingle} event.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - If the caller is not `from`, it must be have been approved to spend ``from``'s tokens via {setApprovalForAll}.
     * - `from` must have a balance of tokens of type `id` of at least `amount`.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
     * acceptance magic value.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 id,
        uint256 amount,
        bytes calldata data
    ) external;

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.
     *
     * Emits a {TransferBatch} event.
     *
     * Requirements:
     *
     * - `ids` and `amounts` must have the same length.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
     * acceptance magic value.
     */
    function safeBatchTransferFrom(
        address from,
        address to,
        uint256[] calldata ids,
        uint256[] calldata amounts,
        bytes calldata data
    ) external;
}

File 32 of 33 : TreasureMetadataStoreState.sol
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "../../shared/AdminableUpgradeable.sol";
import "./ITreasureMetadataStore.sol";
import "@openzeppelin/contracts-upgradeable/utils/structs/EnumerableSetUpgradeable.sol";

abstract contract TreasureMetadataStoreState is AdminableUpgradeable {

    mapping(uint8 => EnumerableSetUpgradeable.UintSet) internal tierToMintableTreasureIds;
    mapping(uint256 => TreasureMetadata) internal treasureIdToMetadata;

    function __TreasureMetadataStoreState_init() internal initializer {
        AdminableUpgradeable.__Adminable_init();
    }
}

File 33 of 33 : LegionMetadataStoreState.sol
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

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

import "../../shared/AdminableUpgradeable.sol";
import "./ILegionMetadataStore.sol";

abstract contract LegionMetadataStoreState is Initializable, AdminableUpgradeable {

    event LegionQuestLevelUp(uint256 indexed _tokenId, uint8 _questLevel);
    event LegionCraftLevelUp(uint256 indexed _tokenId, uint8 _craftLevel);
    event LegionConstellationRankUp(uint256 indexed _tokenId, Constellation indexed _constellation, uint8 _rank);
    event LegionCreated(address indexed _owner, uint256 indexed _tokenId, LegionGeneration _generation, LegionClass _class, LegionRarity _rarity);

    mapping(uint256 => LegionGeneration) internal idToGeneration;
    mapping(uint256 => LegionClass) internal idToClass;
    mapping(uint256 => LegionRarity) internal idToRarity;
    mapping(uint256 => uint256) internal idToOldId;
    mapping(uint256 => uint8) internal idToQuestLevel;
    mapping(uint256 => uint8) internal idToCraftLevel;
    mapping(uint256 => uint8[6]) internal idToConstellationRanks;

    mapping(LegionGeneration => mapping(LegionClass => mapping(LegionRarity => mapping(uint256 => string)))) internal _genToClassToRarityToOldIdToUri;

    function __LegionMetadataStoreState_init() internal initializer {
        AdminableUpgradeable.__Adminable_init();
    }
}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "abi"
      ]
    }
  },
  "libraries": {}
}

Contract ABI

[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_owner","type":"address"},{"indexed":true,"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"CraftingFinished","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_owner","type":"address"},{"indexed":true,"internalType":"uint256","name":"_tokenId","type":"uint256"},{"components":[{"internalType":"bool","name":"wasSuccessful","type":"bool"},{"internalType":"uint256","name":"magicReturned","type":"uint256"},{"internalType":"uint256","name":"rewardId","type":"uint256"},{"internalType":"uint256[]","name":"brokenTreasureIds","type":"uint256[]"},{"internalType":"uint256[]","name":"brokenAmounts","type":"uint256[]"},{"internalType":"uint8","name":"rewardAmount","type":"uint8"}],"indexed":false,"internalType":"struct CraftingOutcome","name":"_outcome","type":"tuple"}],"name":"CraftingRevealed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_owner","type":"address"},{"indexed":true,"internalType":"uint256","name":"_tokenId","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"_requestId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_finishTime","type":"uint256"},{"indexed":false,"internalType":"uint256[]","name":"_treasureIds","type":"uint256[]"},{"indexed":false,"internalType":"uint8[]","name":"_treasureAmounts","type":"uint8[]"}],"name":"CraftingStarted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"addAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_addresses","type":"address[]"}],"name":"addAdmins","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"consumable","outputs":[{"internalType":"contract IConsumable","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"craftingFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"enum RecipeDifficulty","name":"","type":"uint8"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"difficultyToAmountPerTier","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"enum RecipeDifficulty","name":"","type":"uint8"}],"name":"difficultyToLevelUnlocked","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"enum RecipeDifficulty","name":"","type":"uint8"}],"name":"difficultyToRecipeLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"enum RecipeDifficulty","name":"","type":"uint8"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"difficultyToRewards","outputs":[{"internalType":"uint256","name":"consumableId","type":"uint256"},{"internalType":"uint8","name":"amount","type":"uint8"},{"internalType":"uint32","name":"odds","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"enum RecipeDifficulty","name":"","type":"uint8"}],"name":"difficultyToSuccessRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"finishCrafting","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"_tokenIds","type":"uint256[]"}],"name":"finishTokensCrafting","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"isAdmin","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"legion","outputs":[{"internalType":"contract ILegion","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"legionMetadataStore","outputs":[{"internalType":"contract ILegionMetadataStore","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"levelToCPGainedPerRecipe","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"levelToCPNeeded","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"magic","outputs":[{"internalType":"contract IMagic","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxCraftingLevel","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256[]","name":"","type":"uint256[]"},{"internalType":"uint256[]","name":"","type":"uint256[]"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC1155BatchReceived","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC1155Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC721Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"percentReturnedOnFailure","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"randomizer","outputs":[{"internalType":"contract IRandomizer","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"removeAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_addresses","type":"address[]"}],"name":"removeAdmins","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"revealCraftings","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"_tokenIds","type":"uint256[]"}],"name":"revealTokensCraftings","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_randomizerAddress","type":"address"},{"internalType":"address","name":"_treasureAddress","type":"address"},{"internalType":"address","name":"_legionAddress","type":"address"},{"internalType":"address","name":"_treasureMetadataStoreAddress","type":"address"},{"internalType":"address","name":"_legionMetadataStoreAddress","type":"address"},{"internalType":"address","name":"_magicAddress","type":"address"},{"internalType":"address","name":"_treasuryAddress","type":"address"},{"internalType":"address","name":"_consumableAddress","type":"address"}],"name":"setContracts","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint8","name":"_maxCraftingLevel","type":"uint8"},{"internalType":"uint256[]","name":"_levelToCPNeeded","type":"uint256[]"},{"internalType":"uint256[]","name":"_levelToCPGainedPerRecipe","type":"uint256[]"}],"name":"setCraftingLevelSettings","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[3]","name":"_recipeLengths","type":"uint256[3]"},{"internalType":"uint256[3]","name":"_successRates","type":"uint256[3]"},{"internalType":"uint8[5][3]","name":"_treasureAmountPerTier","type":"uint8[5][3]"},{"internalType":"uint8[3]","name":"_levelUnlocked","type":"uint8[3]"}],"name":"setDifficultySettings","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_shouldPause","type":"bool"}],"name":"setPause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"consumableId","type":"uint256"},{"internalType":"uint8","name":"amount","type":"uint8"},{"internalType":"uint32","name":"odds","type":"uint32"}],"internalType":"struct CraftingReward[]","name":"_easyRewards","type":"tuple[]"},{"components":[{"internalType":"uint256","name":"consumableId","type":"uint256"},{"internalType":"uint8","name":"amount","type":"uint8"},{"internalType":"uint32","name":"odds","type":"uint32"}],"internalType":"struct CraftingReward[]","name":"_mediumRewards","type":"tuple[]"},{"components":[{"internalType":"uint256","name":"consumableId","type":"uint256"},{"internalType":"uint8","name":"amount","type":"uint8"},{"internalType":"uint32","name":"odds","type":"uint32"}],"internalType":"struct CraftingReward[]","name":"_hardRewards","type":"tuple[]"}],"name":"setRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_craftingFee","type":"uint256"},{"internalType":"uint8","name":"_percentReturnedOnFailure","type":"uint8"}],"name":"setSimpleSettings","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"enum RecipeDifficulty","name":"_difficulty","type":"uint8"},{"internalType":"uint256[]","name":"_treasureIds","type":"uint256[]"},{"internalType":"uint8[]","name":"_treasureAmounts","type":"uint8[]"}],"name":"startCrafting","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"tokenIdToCP","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"tokenIdToCraftingStartTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"tokenIdToMagicPaid","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"tokenIdToRecipeDifficulty","outputs":[{"internalType":"enum RecipeDifficulty","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"tokenIdToRequestId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"tokenIdToStakedTreasure","outputs":[{"internalType":"uint8","name":"amount","type":"uint8"},{"internalType":"uint256","name":"treasureId","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"treasure","outputs":[{"internalType":"contract ITreasure","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"treasureMetadataStore","outputs":[{"internalType":"contract ITreasureMetadataStore","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"treasury","outputs":[{"internalType":"contract ITreasury","name":"","type":"address"}],"stateMutability":"view","type":"function"}]

608060405234801561001057600080fd5b5061568480620000216000396000f3fe608060405234801561001057600080fd5b50600436106102bb5760003560e01c80637809bf5e11610182578063b7eea374116100e9578063e4551bdf116100a2578063f23a6e611161007c578063f23a6e611461073d578063f2fde38b1461075c578063f71270441461076f578063f74d0d651461077957600080fd5b8063e4551bdf14610702578063e520fc7e14610715578063f10fb5841461072957600080fd5b8063b7eea37414610664578063bc197c8114610677578063bedb86fb14610696578063d7dfe4dd146106a9578063dbf79c97146106bd578063dd26bd84146106de57600080fd5b80638da5cb5b1161013b5780638da5cb5b146105f05780639295bb5a146106015780639ad8d6f7146106095780639c54df641461061c578063a0122ec61461062f578063ad72e1a51461064357600080fd5b80637809bf5e146105515780638108a845146105645780638129fc1c1461059557806387f664261461059d578063897d1d5c146105c95780638a7bf804146105dc57600080fd5b80632e76100f116102265780635d26f573116101df5780635d26f573146104f357806361d027b3146104fb578063675857eb1461050f5780637048027514610523578063715018a61461053657806377f91cc71461053e57600080fd5b80632e76100f146104575780633024a11a14610478578063377e11e01461048b5780634e0226f81461049e578063565188f0146104b15780635c975abb146104e757600080fd5b8063150b7a0211610278578063150b7a02146103995780631711a04a146103d05780631785f53c146103e35780631ded8d88146103f65780631f47dfbe1461040957806324d7806c1461042a57600080fd5b806301ffc9a7146102c0578063042408b3146102e857806304453c1b146103175780630a7bbf4b146103375780630d854646146103585780630fb8416014610384575b600080fd5b6102d36102ce366004614714565b610787565b60405190151581526020015b60405180910390f35b6103096102f636600461474b565b61019b6020526000908152604090205481565b6040519081526020016102df565b6101aa546103259060ff1681565b60405160ff90911681526020016102df565b61030961034536600461474b565b61019a6020526000908152604090205481565b6101975461036c906001600160a01b031681565b6040516001600160a01b0390911681526020016102df565b610397610392366004614818565b6107be565b005b6103b76103a736600461494a565b630a85bd0160e11b949350505050565b6040516001600160e01b031990911681526020016102df565b6103256103de3660046149b1565b610b77565b6103976103f13660046149dd565b610bb1565b610397610404366004614a3c565b610bfd565b610309610417366004614a7d565b6101a46020526000908152604090205481565b6102d36104383660046149dd565b6001600160a01b0316600090815261015f602052604090205460ff1690565b610309610465366004614a7d565b6101a66020526000908152604090205481565b610309610486366004614a7d565b610e37565b610397610499366004614a3c565b610e59565b6103096104ac366004614a7d565b610efb565b6104c46104bf3660046149b1565b610f0c565b6040805193845260ff909216602084015263ffffffff16908201526060016102df565b61012d5460ff166102d3565b610397610f58565b6101985461036c906001600160a01b031681565b6101945461036c906001600160a01b031681565b6103976105313660046149dd565b6110c6565b610397611115565b61039761054c366004614a96565b61114b565b61039761055f366004614b5c565b6113ab565b610588610572366004614a7d565b6101a76020526000908152604090205460ff1681565b6040516102df9190614c0b565b610397611734565b6105b06105ab366004614c33565b6117ae565b6040805160ff90931683526020830191909152016102df565b6103976105d7366004614a3c565b6117ef565b6101965461036c906001600160a01b031681565b60fb546001600160a01b031661036c565b610397611a04565b610397610617366004614c55565b611b6e565b61039761062a366004614a3c565b611c42565b6101955461036c906001600160a01b031681565b610309610651366004614a7d565b6101a56020526000908152604090205481565b610397610672366004614cec565b611cdf565b6103b7610685366004614de4565b63bc197c8160e01b95945050505050565b6103976106a4366004614e9b565b612381565b6101995461036c906001600160a01b031681565b6103096106cb366004614a7d565b6101a36020526000908152604090205481565b6103256106ec36600461474b565b61019d6020526000908152604090205460ff1681565b610397610710366004614eb8565b6123d5565b6101935461036c906001600160a01b031681565b6101925461036c906001600160a01b031681565b6103b761074b366004614ee8565b63f23a6e6160e01b95945050505050565b61039761076a3660046149dd565b612479565b6103096101a95481565b61019f546103259060ff1681565b60006001600160e01b03198216630271189760e51b14806107b857506301ffc9a760e01b6001600160e01b03198316145b92915050565b33600090815261015f602052604090205460ff16806107e057506107e0612511565b6108055760405162461bcd60e51b81526004016107fc90614f4c565b60405180910390fd5b83357fdf87daca02df9cb008fcda558ae984ab92a5826e62dcff2b5180361f9f18ebf2556020848101357f082445bb554fade7877a24b2437efaaa3cb9ee97beb4fd4e4c6f863073eb85c455600260009081526040808701357fef497134997ac3f497d45996287bb42d7b7318af1499095a908382aa5a592ebd5561019b835285357f50a97c7b30cb1a28824c00fb61d93f0784e76a1d9a50667766f7b8f4ed03a65755918501357f1871dda0514920f847a38e1c1a849cdd4f94e8f7f85b81658671fe5ca8ad11ef55908401357f2a1d4f6078f8c36c9403e0edc3d4b2935b0182bca5295cb74bc8b6bfebfa2a5d555b6005811015610ac35782816005811061091157610911614f78565b6020020160208101906109249190614f8e565b6000805261019c6020527f4b419d2fef537193bcacf7d8e3aa1e02cb76a5e91c9927ac0b4328ae4cf88823826005811061096057610960614f78565b602091828204019190066101000a81548160ff021916908360ff1602179055508260016003811061099357610993614f78565b60a0020181600581106109a8576109a8614f78565b6020020160208101906109bb9190614f8e565b600160005261019c6020527fc72eaf8cd3b5c9a905003f86a3aad459ca788a7847e8657dc6013b9edcb24e9482600581106109f8576109f8614f78565b602091828204019190066101000a81548160ff021916908360ff16021790555082600260038110610a2b57610a2b614f78565b60a002018160058110610a4057610a40614f78565b602002016020810190610a539190614f8e565b600260005261019c6020527f6ac6d6b719103e0be90d8f1dc8f262c2aa4b9ba5e23a506ed6f056d83b5bbc708260058110610a9057610a90614f78565b602091828204019190066101000a81548160ff021916908360ff1602179055508080610abb90614fc1565b9150506108f6565b508051600080805261019d60209081527f13dcb3c6205eccc5df5a4a7821d488c75d9d361908855b59d022fe13c7bb4f1d805460ff94851660ff199182161790915590840151600183527f228719b3ab53201bbb41968c40b0b5cdf287f8c98ba3ec9532f722219a6d86ff805491851691831691909117905560409093015160029091527f29ea485743245ef5c5c24b1a283e9aaa2745fd5e9f6154d72f7ef154d10421bc80549093169116179055505050565b61019c6020528160005260406000208160058110610b9457600080fd5b602081049091015460ff601f9092166101000a9004169150829050565b60fb546001600160a01b03163314610bdb5760405162461bcd60e51b81526004016107fc90614fdc565b6001600160a01b0316600090815261015f60205260409020805460ff19169055565b610192546001600160a01b031615801590610c235750610193546001600160a01b031615155b8015610c3a5750610194546001600160a01b031615155b8015610c515750610195546001600160a01b031615155b8015610c685750610196546001600160a01b031615155b8015610c7f5750610198546001600160a01b031615155b8015610c965750610199546001600160a01b031615155b8015610cad5750610197546001600160a01b031615155b610cc95760405162461bcd60e51b81526004016107fc90615011565b61012d5460ff1615610ced5760405162461bcd60e51b81526004016107fc9061503f565b81818080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525050825115159150610d6090505760405162461bcd60e51b815260206004820152600b60248201526a456d70747920617272617960a81b60448201526064016107fc565b333214610d7f5760405162461bcd60e51b81526004016107fc90615069565b60005b82811015610e3157610dbe848483818110610d9f57610d9f614f78565b3360009081526101a26020908152604090912093910201359050612535565b610dfe5760405162461bcd60e51b81526020600482015260116024820152702737ba1037bbb732b210313c903ab9b2b960791b60448201526064016107fc565b610e1f848483818110610e1357610e13614f78565b90506020020135612550565b80610e2981614fc1565b915050610d82565b50505050565b6101a08181548110610e4857600080fd5b600091825260209091200154905081565b60fb546001600160a01b03163314610e835760405162461bcd60e51b81526004016107fc90614fdc565b60005b81811015610ef657600061015f6000858585818110610ea757610ea7614f78565b9050602002016020810190610ebc91906149dd565b6001600160a01b031681526020810191909152604001600020805460ff191691151591909117905580610eee81614fc1565b915050610e86565b505050565b6101a18181548110610e4857600080fd5b61019e6020528160005260406000208181548110610f2957600080fd5b60009182526020909120600290910201805460019091015490925060ff81169150610100900463ffffffff1683565b610192546001600160a01b031615801590610f7e5750610193546001600160a01b031615155b8015610f955750610194546001600160a01b031615155b8015610fac5750610195546001600160a01b031615155b8015610fc35750610196546001600160a01b031615155b8015610fda5750610198546001600160a01b031615155b8015610ff15750610199546001600160a01b031615155b80156110085750610197546001600160a01b031615155b6110245760405162461bcd60e51b81526004016107fc90615011565b61012d5460ff16156110485760405162461bcd60e51b81526004016107fc9061503f565b3332146110675760405162461bcd60e51b81526004016107fc90615069565b3360009081526101a260205260408120611080906128fd565b905060005b81518110156110c2576110b08282815181106110a3576110a3614f78565b6020026020010151612550565b806110ba81614fc1565b915050611085565b5050565b60fb546001600160a01b031633146110f05760405162461bcd60e51b81526004016107fc90614fdc565b6001600160a01b0316600090815261015f60205260409020805460ff19166001179055565b60fb546001600160a01b0316331461113f5760405162461bcd60e51b81526004016107fc90614fdc565b611149600061290a565b565b33600090815261015f602052604090205460ff168061116d575061116d612511565b6111895760405162461bcd60e51b81526004016107fc90614f4c565b60008560ff16116111cc5760405162461bcd60e51b815260206004820152600d60248201526c109859081b585e081b195d995b609a1b60448201526064016107fc565b6111d760018661508f565b60ff16831461121e5760405162461bcd60e51b81526020600482015260136024820152724e6f7420656e6f75676820435020737465707360681b60448201526064016107fc565b61122960018661508f565b60ff16811461127a5760405162461bcd60e51b815260206004820152601a60248201527f4e6f7420656e6f756768204350206761696e656420737465707300000000000060448201526064016107fc565b61019f805460ff191660ff87161790556112976101a060006145c7565b6112a46101a160006145c7565b6101a08054600181810190925560007f7980fe0f714a613298681d64b7b8ffa7b148338dd52429f307d72798d5c317c49091018190556101a18054928301815581527f138323e2a914e847043e23cddd114fae8437deb6d72c040f1025356455849bda9091018190555b61131960018761508f565b60ff168110156113a3576101a085858381811061133857611338614f78565b835460018101855560009485526020948590209190940292909201359190920155506101a183838381811061136f5761136f614f78565b835460018101855560009485526020948590209190940292909201359190920155508061139b81614fc1565b91505061130e565b505050505050565b33600090815261015f602052604090205460ff16806113cd57506113cd612511565b6113e95760405162461bcd60e51b81526004016107fc90614f4c565b60408051606081018252600080825260016020830152600292820192909252905b600381101561172a5761019e600083836003811061142a5761142a614f78565b6020020151600281111561144057611440614bf5565b600281111561145157611451614bf5565b8152602001908152602001600020600061146b91906145e5565b6060600083836003811061148157611481614f78565b6020020151600281111561149757611497614bf5565b14156114f7578888808060200260200160405190810160405280939291908181526020016000905b828210156114eb576114dc606083028601368190038101906150c4565b815260200190600101906114bf565b505050505090506115cb565b600183836003811061150b5761150b614f78565b6020020151600281111561152157611521614bf5565b1415611575578686808060200260200160405190810160405280939291908181526020016000905b828210156114eb57611566606083028601368190038101906150c4565b81526020019060010190611549565b8484808060200260200160405190810160405280939291908181526020016000905b828210156115c3576115b4606083028601368190038101906150c4565b81526020019060010190611597565b505050505090505b6000805b82518110156116d75761019e60008686600381106115ef576115ef614f78565b6020020151600281111561160557611605614bf5565b600281111561161657611616614bf5565b815260200190815260200160002083828151811061163657611636614f78565b60209081029190910181015182546001818101855560009485529383902082516002909202019081559181015191909201805460409093015163ffffffff166101000264ffffffffff1990931660ff9092169190911791909117905582518390829081106116a6576116a6614f78565b60200260200101516040015163ffffffff16826116c3919061512c565b9150806116cf81614fc1565b9150506115cf565b5080620186a0146117155760405162461bcd60e51b8152602060048201526008602482015267426164206f64647360c01b60448201526064016107fc565b5050808061172290614fc1565b91505061140a565b5050505050505050565b600054610100900460ff1661174f5760005460ff1615611753565b303b155b61176f5760405162461bcd60e51b81526004016107fc90615144565b600054610100900460ff16158015611791576000805461ffff19166101011790555b61179961295c565b80156117ab576000805461ff00191690555b50565b6101a860205281600052604060002081815481106117cb57600080fd5b60009182526020909120600290910201805460019091015460ff9091169250905082565b610192546001600160a01b0316158015906118155750610193546001600160a01b031615155b801561182c5750610194546001600160a01b031615155b80156118435750610195546001600160a01b031615155b801561185a5750610196546001600160a01b031615155b80156118715750610198546001600160a01b031615155b80156118885750610199546001600160a01b031615155b801561189f5750610197546001600160a01b031615155b6118bb5760405162461bcd60e51b81526004016107fc90615011565b61012d5460ff16156118df5760405162461bcd60e51b81526004016107fc9061503f565b8181808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152505082511515915061195290505760405162461bcd60e51b815260206004820152600b60248201526a456d70747920617272617960a81b60448201526064016107fc565b3332146119715760405162461bcd60e51b81526004016107fc90615069565b60005b82811015610e3157611991848483818110610d9f57610d9f614f78565b6119d15760405162461bcd60e51b81526020600482015260116024820152702737ba1037bbb732b210313c903ab9b2b960791b60448201526064016107fc565b6119f28484838181106119e6576119e6614f78565b905060200201356129c1565b806119fc81614fc1565b915050611974565b610192546001600160a01b031615801590611a2a5750610193546001600160a01b031615155b8015611a415750610194546001600160a01b031615155b8015611a585750610195546001600160a01b031615155b8015611a6f5750610196546001600160a01b031615155b8015611a865750610198546001600160a01b031615155b8015611a9d5750610199546001600160a01b031615155b8015611ab45750610197546001600160a01b031615155b611ad05760405162461bcd60e51b81526004016107fc90615011565b61012d5460ff1615611af45760405162461bcd60e51b81526004016107fc9061503f565b333214611b135760405162461bcd60e51b81526004016107fc90615069565b3360009081526101a260205260408120611b2c906128fd565b905060005b81518110156110c257611b5c828281518110611b4f57611b4f614f78565b60200260200101516129c1565b80611b6681614fc1565b915050611b31565b33600090815261015f602052604090205460ff1680611b905750611b90612511565b611bac5760405162461bcd60e51b81526004016107fc90614f4c565b61019280546001600160a01b03199081166001600160a01b039a8b161790915561019380548216988a1698909817909755610194805488169689169690961790955561019580548716948816949094179093556101968054861692871692909217909155610197805485169186169190911790556101988054841691851691909117905561019980549092169216919091179055565b60fb546001600160a01b03163314611c6c5760405162461bcd60e51b81526004016107fc90614fdc565b60005b81811015610ef657600161015f6000858585818110611c9057611c90614f78565b9050602002016020810190611ca591906149dd565b6001600160a01b031681526020810191909152604001600020805460ff191691151591909117905580611cd781614fc1565b915050611c6f565b61012d5460ff1615611d035760405162461bcd60e51b81526004016107fc9061503f565b610192546001600160a01b031615801590611d295750610193546001600160a01b031615155b8015611d405750610194546001600160a01b031615155b8015611d575750610195546001600160a01b031615155b8015611d6e5750610196546001600160a01b031615155b8015611d855750610198546001600160a01b031615155b8015611d9c5750610199546001600160a01b031615155b8015611db35750610197546001600160a01b031615155b611dcf5760405162461bcd60e51b81526004016107fc90615011565b333214611dee5760405162461bcd60e51b81526004016107fc90615069565b61019860009054906101000a90046001600160a01b03166001600160a01b031663ca1709556040518163ffffffff1660e01b815260040160206040518083038186803b158015611e3d57600080fd5b505afa158015611e51573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e759190615192565b611ec15760405162461bcd60e51b815260206004820152601860248201527f42726964676520576f726c64206e6f7420706f7765726564000000000000000060448201526064016107fc565b610196546040516378afdef960e11b8152600481018890526000916001600160a01b03169063f15fbdf2906024016101806040518083038186803b158015611f0857600080fd5b505afa158015611f1c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f409190615248565b9050600281516002811115611f5757611f57614bf5565b1415611fa55760405162461bcd60e51b815260206004820152601960248201527f43616e6e6f74206372616674207769746820726563727569740000000000000060448201526064016107fc565b600061019d6000886002811115611fbe57611fbe614bf5565b6002811115611fcf57611fcf614bf5565b8152602081019190915260400160002054608083015160ff9182169250168111156120355760405162461bcd60e51b8152602060048201526016602482015275111a59999a58dd5b1d081b9bdd081d5b9b1bd8dad95960521b60448201526064016107fc565b3360009081526101a26020526040902061204f9089612f2a565b5060008881526101a46020908152604080832042905561019254815163433c53d960e11b815291516001600160a01b0390911692638678a7b2926004808201939182900301818787803b1580156120a557600080fd5b505af11580156120b9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120dd91906152df565b60008a81526101a5602090815260408083208490556101a790915290208054919250899160ff1916600183600281111561211957612119614bf5565b021790555061218d898989898080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525050604080516020808d0282810182019093528c82529093508c92508b918291850190849080828437600092019190915250612f3692505050565b610197546101a9546040516323b872dd60e01b815233600482015230602482015260448101919091526000916001600160a01b0316906323b872dd90606401602060405180830381600087803b1580156121e657600080fd5b505af11580156121fa573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061221e9190615192565b9050806122665760405162461bcd60e51b815260206004820152601660248201527526b0b3b4b1903234b2103737ba103a3930b739b332b960511b60448201526064016107fc565b6101a95460008b81526101a6602052604090819020919091556101945490516383291f8760e01b8152336004820152306024820152604481018c90526001600160a01b03909116906383291f8790606401600060405180830381600087803b1580156122d157600080fd5b505af11580156122e5573d6000803e3d6000fd5b50505050818a336001600160a01b03167f0aa5906bf64c82ea74f27ca0729e93311ed2636f4c968d2ae9a24fbae87aa07c61019a60008e600281111561232d5761232d614bf5565b600281111561233e5761233e614bf5565b81526020019081526020016000205442612358919061512c565b8c8c8c8c60405161236d9594939291906152f8565b60405180910390a450505050505050505050565b33600090815261015f602052604090205460ff16806123a357506123a3612511565b6123bf5760405162461bcd60e51b81526004016107fc90614f4c565b80156123cd576117ab6133f2565b6117ab613469565b33600090815261015f602052604090205460ff16806123f757506123f7612511565b6124135760405162461bcd60e51b81526004016107fc90614f4c565b60648160ff16111561245c5760405162461bcd60e51b8152602060048201526012602482015271109859081c99599d5b99081c195c98d95b9d60721b60448201526064016107fc565b6101a9919091556101aa805460ff191660ff909216919091179055565b60fb546001600160a01b031633146124a35760405162461bcd60e51b81526004016107fc90614fdc565b6001600160a01b0381166125085760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016107fc565b6117ab8161290a565b60003361252660fb546001600160a01b031690565b6001600160a01b031614905090565b600081815260018301602052604081205415155b9392505050565b60008181526101a56020526040902054801561256a575050565b60008281526101a7602052604081205460ff169061019a9082600281111561259457612594614bf5565b60028111156125a5576125a5614bf5565b8152602001908152602001600020546101a46000858152602001908152602001600020546125d3919061512c565b4210156125df57505050565b60008381526101a86020908152604080832080548251818502810185019093528083529192909190849084015b8282101561264e5760008481526020908190206040805180820190915260028502909101805460ff16825260019081015482840152908352909201910161260c565b505050509050600081516001600160401b0381111561266f5761266f614779565b604051908082528060200260200182016040528015612698578160200160208202803683370190505b509050600082516001600160401b038111156126b6576126b6614779565b6040519080825280602002602001820160405280156126df578160200160208202803683370190505b5090506000805b845181101561279257600085828151811061270357612703614f78565b60200260200101519050600081602001511180156127245750805160ff1615155b1561277f57806020015185848151811061274057612740614f78565b602002602001018181525050806000015160ff1684848151811061276657612766614f78565b60209081029190910101528261277b81614fc1565b9350505b508061278a81614fc1565b9150506126e6565b5080156128035761019354604051631759616b60e11b81526001600160a01b0390911690632eb2c2d6906127d09030903390889088906004016153b9565b600060405180830381600087803b1580156127ea57600080fd5b505af11580156127fe573d6000803e3d6000fd5b505050505b3360009081526101a26020526040902061281d90886134e5565b5060008781526101a86020526040812061283691614606565b60008781526101a760209081526040808320805460ff191690556101a4909152808220919091556101945490516383291f8760e01b8152306004820152336024820152604481018990526001600160a01b03909116906383291f8790606401600060405180830381600087803b1580156128af57600080fd5b505af11580156128c3573d6000803e3d6000fd5b50506040518992503391507f23f7783750e2685b1c6ce3a0e6277237e34e907e6defe8cfd0984430c184013e90600090a350505050505050565b60606000612549836134f1565b60fb80546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b600054610100900460ff166129775760005460ff161561297b565b303b155b6129975760405162461bcd60e51b81526004016107fc90615144565b600054610100900460ff161580156129b9576000805461ffff19166101011790555b61179961354d565b60008181526101a56020526040902054806129da575050565b6101925460405163f030210760e01b8152600481018390526001600160a01b039091169063f03021079060240160206040518083038186803b158015612a1f57600080fd5b505afa158015612a33573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a579190615192565b612a5f575050565b61019254604051634ad30a7560e01b8152600481018390526000916001600160a01b031690634ad30a759060240160206040518083038186803b158015612aa557600080fd5b505afa158015612ab9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612add91906152df565b60008481526101a76020526040808220546101965491516378afdef960e11b81526004810188905293945060ff16926001600160a01b039091169063f15fbdf2906024016101806040518083038186803b158015612b3a57600080fd5b505afa158015612b4e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b729190615248565b90506000612b83620186a08561542a565b60008781526101a6602052604081205491925061019b81866002811115612bac57612bac614bf5565b6002811115612bbd57612bbd614bf5565b8152602001908152602001600020548310905060008060608060008515612c6f5760408051602081018d90529081018c90526060016040516020818303038152906040528051906020012060001c9a50612c178a8c6135b2565b60408051602081018f90529081018e905291965094506060016040516020818303038152906040528051906020012060001c9a50612c558d8c61387c565b60808b01519194509250612c6a908e90613cad565b612d6c565b6101aa54606490612c839060ff168961543e565b612c8d919061545d565b90508015612d6c576101975460405163a9059cbb60e01b8152336004820152602481018390526000916001600160a01b03169063a9059cbb90604401602060405180830381600087803b158015612ce357600080fd5b505af1158015612cf7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d1b9190615192565b905080612d6a5760405162461bcd60e51b815260206004820152601d60248201527f4d61676963206661696c656420746f206265207265696d62757273656400000060448201526064016107fc565b505b8087118015612d7b5750600087115b15612e915761019754610198546001600160a01b039182169163a9059cbb9116612da5848b615471565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401602060405180830381600087803b158015612deb57600080fd5b505af1158015612dff573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e239190615192565b50610198546001600160a01b03166359193fc5612e40838a615471565b6040518263ffffffff1660e01b8152600401612e5e91815260200190565b600060405180830381600087803b158015612e7857600080fd5b505af1158015612e8c573d6000803e3d6000fd5b505050505b60008d81526101a5602090815260408083208390556101a6825280832092909255815160c0810183528815158152908101839052808201879052606081018590526080810184905260ff861660a082015290518e9133917fd65ad94579465d7eaed3b4443ce853cf5bcd3e01d3599ea3ca6769ea57fadd5d91612f1391615488565b60405180910390a350505050505050505050505050565b60006125498383613e1c565b60008251118015612f48575080518251145b612f895760405162461bcd60e51b8152602060048201526012602482015271109859081d1c99585cdd5c99481a5b9c1d5d60721b60448201526064016107fc565b600061019c6000856002811115612fa257612fa2614bf5565b6002811115612fb357612fb3614bf5565b815260208101919091526040908101600020815160a0810190925260058282826020028201916000905b825461010083900a900460ff16815260206001928301818104948501949093039092029101808411612fdd5750949550600094506005935061301e92505050565b604051908082528060200260200182016040528015613047578160200160208202803683370190505b509050600083516001600160401b0381111561306557613065614779565b60405190808252806020026020018201604052801561308e578160200160208202803683370190505b50905060005b85518110156132dc576101955486516000916001600160a01b03169063ed4706d4908990859081106130c8576130c8614f78565b60200260200101516040518263ffffffff1660e01b81526004016130ee91815260200190565b60a06040518083038186803b15801561310657600080fd5b505afa15801561311a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061313e91906154fb565b90506001816020015160ff161015801561316057506005816020015160ff1611155b6131a05760405162461bcd60e51b81526020600482015260116024820152702130b2103a3932b0b9bab932903a34b2b960791b60448201526064016107fc565b8582815181106131b2576131b2614f78565b602002602001015184600183602001516131cc919061508f565b60ff16815181106131df576131df614f78565b602002602001018181516131f3919061558b565b60ff16905250855186908390811061320d5761320d614f78565b602002602001015160ff1683838151811061322a5761322a614f78565b6020026020010181815250506101a860008a8152602001908152602001600020604051806040016040528088858151811061326757613267614f78565b602002602001015160ff16815260200189858151811061328957613289614f78565b6020908102919091018101519091528254600180820185556000948552938290208351600290920201805460ff191660ff90921691909117815591015191015550806132d481614fc1565b915050613094565b5060005b825181101561337f578281815181106132fb576132fb614f78565b602002602001015160ff1684826005811061331857613318614f78565b602002015160ff161461336d5760405162461bcd60e51b815260206004820152601b60248201527f496e636f727265637420616d6f756e7420666f7220726563697065000000000060448201526064016107fc565b8061337781614fc1565b9150506132e0565b5061019354604051631759616b60e11b81526001600160a01b0390911690632eb2c2d6906133b790339030908a9087906004016153b9565b600060405180830381600087803b1580156133d157600080fd5b505af11580156133e5573d6000803e3d6000fd5b5050505050505050505050565b61012d5460ff16156134165760405162461bcd60e51b81526004016107fc9061503f565b61012d805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25861344c3390565b6040516001600160a01b03909116815260200160405180910390a1565b61012d5460ff166134b35760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b60448201526064016107fc565b61012d805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa3361344c565b60006125498383613e6b565b60608160000180548060200260200160405190810160405280929190818152602001828054801561354157602002820191906000526020600020905b81548152602001906001019080831161352d575b50505050509050919050565b600054610100900460ff166135685760005460ff161561356c565b303b155b6135885760405162461bcd60e51b81526004016107fc90615144565b600054610100900460ff161580156135aa576000805461ffff19166101011790555b611799613f5e565b600080600061019e60008660028111156135ce576135ce614bf5565b60028111156135df576135df614bf5565b8152602001908152602001600020805480602002602001604051908101604052809291908181526020016000905b8282101561366257600084815260209081902060408051606081018252600286029092018054835260019081015460ff811684860152610100900463ffffffff1691830191909152908352909201910161360d565b50505050905060008151116136b95760405162461bcd60e51b815260206004820152601d60248201527f4e6f20726577617264732073657420666f7220646966666963756c747900000060448201526064016107fc565b60006136c8620186a08661542a565b90506000805b835181101561382c578381815181106136e9576136e9614f78565b60200260200101516040015163ffffffff1682613706919061512c565b91508183101561381a576101995484516001600160a01b039091169063156e29f690339087908590811061373c5761373c614f78565b60200260200101516000015187858151811061375a5761375a614f78565b60209081029190910181015101516040516001600160e01b031960e086901b1681526001600160a01b039093166004840152602483019190915260ff166044820152606401600060405180830381600087803b1580156137b957600080fd5b505af11580156137cd573d6000803e3d6000fd5b505050508381815181106137e3576137e3614f78565b60200260200101516000015184828151811061380157613801614f78565b6020026020010151602001519550955050505050613875565b8061382481614fc1565b9150506136ce565b5060405162461bcd60e51b815260206004820152601960248201527f526577617264206f6464732061726520696e636f72726563740000000000000060448201526064016107fc565b9250929050565b60608060006101a86000868152602001908152602001600020805480602002602001604051908101604052809291908181526020016000905b828210156138f75760008481526020908190206040805180820190915260028502909101805460ff1682526001908101548284015290835290920191016138b5565b505050509050600081516001600160401b0381111561391857613918614779565b604051908082528060200260200182016040528015613941578160200160208202803683370190505b509050600082516001600160401b0381111561395f5761395f614779565b604051908082528060200260200182016040528015613988578160200160208202803683370190505b5090506000805b8451811015613c295760008582815181106139ac576139ac614f78565b6020908102919091018101516101955491810151604051633b51c1b560e21b81529193506000926001600160a01b03169163ed4706d4916139f39160040190815260200190565b60a06040518083038186803b158015613a0b57600080fd5b505afa158015613a1f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613a4391906154fb565b825190915060ff1660005b81811015613be2576000613a65620186a08e61542a565b905080846040015163ffffffff161015613b9f578460200151898881518110613a9057613a90614f78565b6020026020010181815250506101a860008f81526020019081526020016000208681548110613ac157613ac1614f78565b600091825260208220600290910201805460ff1691613adf836155b0565b91906101000a81548160ff021916908360ff16021790555050878781518110613b0a57613b0a614f78565b602002602001018051809190613b1f90614fc1565b905250608084015115613b9f57610199546080850151604051630ab714fb60e11b81523360048201526024810191909152600160448201526001600160a01b039091169063156e29f690606401600060405180830381600087803b158015613b8657600080fd5b505af1158015613b9a573d6000803e3d6000fd5b505050505b60408051602081018f90529081018e90526060016040516020818303038152906040528051906020012060001c9c50508080613bda90614fc1565b915050613a4e565b506000868681518110613bf757613bf7614f78565b60200260200101511115613c135784613c0f81614fc1565b9550505b5050508080613c2190614fc1565b91505061398f565b508015613ca0576101935461019854604051631759616b60e11b81526001600160a01b0392831692632eb2c2d692613c6d92309290911690889088906004016153b9565b600060405180830381600087803b158015613c8757600080fd5b505af1158015613c9b573d6000803e3d6000fd5b505050505b5090969095509350505050565b61019f5460ff90811690821610613cc2575050565b6101a18160ff1681548110613cd957613cd9614f78565b90600052602060002001546101a360008481526020019081526020016000206000828254613d07919061512c565b90915550505b61019f5460ff908116908216108015613d5b57506101a08160ff1681548110613d3857613d38614f78565b90600052602060002001546101a360008481526020019081526020016000205410155b156110c2576101a08160ff1681548110613d7757613d77614f78565b90600052602060002001546101a360008481526020019081526020016000206000828254613da59190615471565b90915550506101965460405163ccd5efbf60e01b8152600481018490526001600160a01b039091169063ccd5efbf90602401600060405180830381600087803b158015613df157600080fd5b505af1158015613e05573d6000803e3d6000fd5b505050508080613e14906155cd565b915050613d0d565b6000818152600183016020526040812054613e63575081546001818101845560008481526020808220909301849055845484825282860190935260409020919091556107b8565b5060006107b8565b60008181526001830160205260408120548015613f54576000613e8f600183615471565b8554909150600090613ea390600190615471565b9050818114613f08576000866000018281548110613ec357613ec3614f78565b9060005260206000200154905080876000018481548110613ee657613ee6614f78565b6000918252602080832090910192909255918252600188019052604090208390555b8554869080613f1957613f196155ed565b6001900381819060005260206000200160009055905585600101600086815260200190815260200160002060009055600193505050506107b8565b60009150506107b8565b600054610100900460ff16613f795760005460ff1615613f7d565b303b155b613f995760405162461bcd60e51b81526004016107fc90615144565b600054610100900460ff16158015613fbb576000805461ffff19166101011790555b613fc361438e565b613fcb6143f3565b613fd3614422565b6170807fdf87daca02df9cb008fcda558ae984ab92a5826e62dcff2b5180361f9f18ebf25561a8c07f082445bb554fade7877a24b2437efaaa3cb9ee97beb4fd4e4c6f863073eb85c45561e1007fef497134997ac3f497d45996287bb42d7b7318af1499095a908382aa5a592ebd5562015f907f50a97c7b30cb1a28824c00fb61d93f0784e76a1d9a50667766f7b8f4ed03a6578190557f1871dda0514920f847a38e1c1a849cdd4f94e8f7f85b81658671fe5ca8ad11ef8190557f2a1d4f6078f8c36c9403e0edc3d4b2935b0182bca5295cb74bc8b6bfebfa2a5d557f13dcb3c6205eccc5df5a4a7821d488c75d9d361908855b59d022fe13c7bb4f1d8054600160ff1991821681179092557f228719b3ab53201bbb41968c40b0b5cdf287f8c98ba3ec9532f722219a6d86ff8054821660031790557f29ea485743245ef5c5c24b1a283e9aaa2745fd5e9f6154d72f7ef154d10421bc805460059216821790556040805160a0810182526000808252602080830182905292820181905260608201949094526002608082015292805261019c9052614194917f4b419d2fef537193bcacf7d8e3aa1e02cb76a5e91c9927ac0b4328ae4cf8882391614627565b506040805160a081018252600080825260208083018290526001938301849052600260608401819052608084015292905261019c9091526141f8907fc72eaf8cd3b5c9a905003f86a3aad459ca788a7847e8657dc6013b9edcb24e94906005614627565b506040805160a08101825260018082526020808301829052928201526002606082018190526080820181905260005261019c90915261425a907f6ac6d6b719103e0be90d8f1dc8f262c2aa4b9ba5e23a506ed6f056d83b5bbc70906005614627565b5061019f805460ff199081166006179091556101a080546001818101835560007f7980fe0f714a613298681d64b7b8ffa7b148338dd52429f307d72798d5c317c4928301819055835480830185556064908401558354808301855560c8908401558354808301855561019090840155835480830185556105dc9084015583548083019094556107d093909201929092556101a1805480840182558183527f138323e2a914e847043e23cddd114fae8437deb6d72c040f1025356455849bda9081019290925580548084018255600a908301558054808401825560149083015580548084018255601e90830155805480840182556028908301558054928301905560329101556101aa8054909116605a17905568015af1d78b58c400006101a95580156117ab576000805461ff001916905550565b600054610100900460ff166143a95760005460ff16156143ad565b303b155b6143c95760405162461bcd60e51b81526004016107fc90615144565b600054610100900460ff161580156143eb576000805461ffff19166101011790555b611799614459565b600054610100900460ff1661441a5760405162461bcd60e51b81526004016107fc90615603565b6111496144ce565b600054610100900460ff166144495760405162461bcd60e51b81526004016107fc90615603565b6144516144ce565b61441a6144ce565b600054610100900460ff166144745760005460ff1615614478565b303b155b6144945760405162461bcd60e51b81526004016107fc90615144565b600054610100900460ff161580156144b6576000805461ffff19166101011790555b6144be6144f5565b6144c661452c565b6117996133f2565b600054610100900460ff166111495760405162461bcd60e51b81526004016107fc90615603565b600054610100900460ff1661451c5760405162461bcd60e51b81526004016107fc90615603565b6145246144ce565b611149614563565b600054610100900460ff166145535760405162461bcd60e51b81526004016107fc90615603565b61455b6144ce565b611149614593565b600054610100900460ff1661458a5760405162461bcd60e51b81526004016107fc90615603565b6111493361290a565b600054610100900460ff166145ba5760405162461bcd60e51b81526004016107fc90615603565b61012d805460ff19169055565b50805460008255906000526020600020908101906117ab91906146ba565b50805460008255600202906000526020600020908101906117ab91906146cf565b50805460008255600202906000526020600020908101906117ab91906146f4565b6001830191839082156146aa5791602002820160005b8382111561467b57835183826101000a81548160ff021916908360ff160217905550926020019260010160208160000104928301926001030261463d565b80156146a85782816101000a81549060ff021916905560010160208160000104928301926001030261467b565b505b506146b69291506146ba565b5090565b5b808211156146b657600081556001016146bb565b5b808211156146b6576000815560018101805464ffffffffff191690556002016146d0565b5b808211156146b657805460ff19168155600060018201556002016146f5565b60006020828403121561472657600080fd5b81356001600160e01b03198116811461254957600080fd5b600381106117ab57600080fd5b60006020828403121561475d57600080fd5b81356125498161473e565b80606081018310156107b857600080fd5b634e487b7160e01b600052604160045260246000fd5b60405160e081016001600160401b03811182821017156147b1576147b1614779565b60405290565b604051606081016001600160401b03811182821017156147b1576147b1614779565b604051601f8201601f191681016001600160401b038111828210171561480157614801614779565b604052919050565b60ff811681146117ab57600080fd5b60008060008061030080868803121561483057600080fd5b61483a8787614768565b94506148498760608801614768565b93506102a086018781111561485d57600080fd5b60c087019350876102bf88011261487357600080fd5b61487b6147b7565b91870191808984111561488d57600080fd5b838310156148b15782356148a081614809565b82526020928301929091019061488d565b969995985093965050505050565b80356001600160a01b03811681146148d657600080fd5b919050565b600082601f8301126148ec57600080fd5b81356001600160401b0381111561490557614905614779565b614918601f8201601f19166020016147d9565b81815284602083860101111561492d57600080fd5b816020850160208301376000918101602001919091529392505050565b6000806000806080858703121561496057600080fd5b614969856148bf565b9350614977602086016148bf565b92506040850135915060608501356001600160401b0381111561499957600080fd5b6149a5878288016148db565b91505092959194509250565b600080604083850312156149c457600080fd5b82356149cf8161473e565b946020939093013593505050565b6000602082840312156149ef57600080fd5b612549826148bf565b60008083601f840112614a0a57600080fd5b5081356001600160401b03811115614a2157600080fd5b6020830191508360208260051b850101111561387557600080fd5b60008060208385031215614a4f57600080fd5b82356001600160401b03811115614a6557600080fd5b614a71858286016149f8565b90969095509350505050565b600060208284031215614a8f57600080fd5b5035919050565b600080600080600060608688031215614aae57600080fd5b8535614ab981614809565b945060208601356001600160401b0380821115614ad557600080fd5b614ae189838a016149f8565b90965094506040880135915080821115614afa57600080fd5b50614b07888289016149f8565b969995985093965092949392505050565b60008083601f840112614b2a57600080fd5b5081356001600160401b03811115614b4157600080fd5b60208301915083602060608302850101111561387557600080fd5b60008060008060008060608789031215614b7557600080fd5b86356001600160401b0380821115614b8c57600080fd5b614b988a838b01614b18565b90985096506020890135915080821115614bb157600080fd5b614bbd8a838b01614b18565b90965094506040890135915080821115614bd657600080fd5b50614be389828a01614b18565b979a9699509497509295939492505050565b634e487b7160e01b600052602160045260246000fd5b6020810160038310614c2d57634e487b7160e01b600052602160045260246000fd5b91905290565b60008060408385031215614c4657600080fd5b50508035926020909101359150565b600080600080600080600080610100898b031215614c7257600080fd5b614c7b896148bf565b9750614c8960208a016148bf565b9650614c9760408a016148bf565b9550614ca560608a016148bf565b9450614cb360808a016148bf565b9350614cc160a08a016148bf565b9250614ccf60c08a016148bf565b9150614cdd60e08a016148bf565b90509295985092959890939650565b60008060008060008060808789031215614d0557600080fd5b863595506020870135614d178161473e565b945060408701356001600160401b0380821115614d3357600080fd5b614d3f8a838b016149f8565b90965094506060890135915080821115614d5857600080fd5b50614be389828a016149f8565b600082601f830112614d7657600080fd5b813560206001600160401b03821115614d9157614d91614779565b8160051b614da08282016147d9565b9283528481018201928281019087851115614dba57600080fd5b83870192505b84831015614dd957823582529183019190830190614dc0565b979650505050505050565b600080600080600060a08688031215614dfc57600080fd5b614e05866148bf565b9450614e13602087016148bf565b935060408601356001600160401b0380821115614e2f57600080fd5b614e3b89838a01614d65565b94506060880135915080821115614e5157600080fd5b614e5d89838a01614d65565b93506080880135915080821115614e7357600080fd5b50614e80888289016148db565b9150509295509295909350565b80151581146117ab57600080fd5b600060208284031215614ead57600080fd5b813561254981614e8d565b60008060408385031215614ecb57600080fd5b823591506020830135614edd81614809565b809150509250929050565b600080600080600060a08688031215614f0057600080fd5b614f09866148bf565b9450614f17602087016148bf565b9350604086013592506060860135915060808601356001600160401b03811115614f4057600080fd5b614e80888289016148db565b6020808252601290820152712737ba1030b236b4b71037b91037bbb732b960711b604082015260600190565b634e487b7160e01b600052603260045260246000fd5b600060208284031215614fa057600080fd5b813561254981614809565b634e487b7160e01b600052601160045260246000fd5b6000600019821415614fd557614fd5614fab565b5060010190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60208082526014908201527310dbdb9d1c9858dd1cc8185c995b89dd081cd95d60621b604082015260600190565b60208082526010908201526f14185d5cd8589b194e881c185d5cd95960821b604082015260600190565b6020808252600c908201526b4e6f20636f6e74726163747360a01b604082015260600190565b600060ff821660ff8416808210156150a9576150a9614fab565b90039392505050565b63ffffffff811681146117ab57600080fd5b6000606082840312156150d657600080fd5b604051606081018181106001600160401b03821117156150f8576150f8614779565b60405282358152602083013561510d81614809565b60208201526040830135615120816150b2565b60408201529392505050565b6000821982111561513f5761513f614fab565b500190565b6020808252602e908201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160408201526d191e481a5b9a5d1a585b1a5e995960921b606082015260800190565b6000602082840312156151a457600080fd5b815161254981614e8d565b600681106117ab57600080fd5b80516148d6816151af565b80516148d681614809565b600082601f8301126151e357600080fd5b60405160c081018181106001600160401b038211171561520557615205614779565b6040528060c084018581111561521a57600080fd5b845b8181101561523d57805161522f81614809565b83526020928301920161521c565b509195945050505050565b6000610180828403121561525b57600080fd5b61526361478f565b825161526e8161473e565b81526020830151600a811061528257600080fd5b6020820152615293604084016151bc565b60408201526152a4606084016151c7565b60608201526152b5608084016151c7565b60808201526152c78460a085016151d2565b60a0820152610160929092015160c083015250919050565b6000602082840312156152f157600080fd5b5051919050565b8581526000602060608184015285606084015260018060fb1b0386111561531e57600080fd5b8560051b808860808601378301838103608090810160408601528101859052859060009060a0015b8682101561537057823561535981614809565b60ff16815291830191600191909101908301615346565b9a9950505050505050505050565b600081518084526020808501945080840160005b838110156153ae57815187529582019590820190600101615392565b509495945050505050565b6001600160a01b0385811682528416602082015260a0604082018190526000906153e59083018561537e565b82810360608401526153f7818561537e565b838103608090940193909352505060008152602001949350505050565b634e487b7160e01b600052601260045260246000fd5b60008261543957615439615414565b500690565b600081600019048311821515161561545857615458614fab565b500290565b60008261546c5761546c615414565b500490565b60008282101561548357615483614fab565b500390565b6020815281511515602082015260208201516040820152604082015160608201526000606083015160c060808401526154c460e084018261537e565b90506080840151601f198483030160a08501526154e1828261537e565b91505060ff60a08501511660c08401528091505092915050565b600060a0828403121561550d57600080fd5b60405160a081018181106001600160401b038211171561552f5761552f614779565b604052825161553d816151af565b8152602083015161554d81614809565b60208201526040830151615560816150b2565b6040820152606083015161557381614e8d565b60608201526080928301519281019290925250919050565b600060ff821660ff84168060ff038211156155a8576155a8614fab565b019392505050565b600060ff8216806155c3576155c3614fab565b6000190192915050565b600060ff821660ff8114156155e4576155e4614fab565b60010192915050565b634e487b7160e01b600052603160045260246000fd5b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b60608201526080019056fea26469706673582212208572eed4704b46418daa8326f422019c0ddcc1b3a5fd6a52e76100efb31ae7ae64736f6c63430008090033

Block Transaction Gas Used Reward
Age Block Fee Address BC Fee Address Voting Power Jailed Incoming
Block Uncle Number Difficulty Gas Used Reward
Loading
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.