Contract 0xaeF876EE95d0fEEAF5A5DeDd4531cBA074519BEb

 

Contract Overview

Balance:
0 MATIC

MATIC Value:
$0.00

Token:
Txn Hash Method
Block
From
To
Value [Txn Fee]
0xeb5a25ef854cb91abcf8aec4859dac620c1281e8f657d81038e9ea30cf9a18fdSafe Transfer Fr...191824682021-09-16 21:17:133 days 14 hrs ago0xce7bf1ac9e0baba188d1a297ad64bde16cf2967c IN  0xaef876ee95d0feeaf5a5dedd4531cba074519beb0 MATIC0.0122797
0x419981916a5e1a28c7406435392af6a0c9707dbd31b3799b552d0b632297b5cfSafe Transfer Fr...191824412021-09-16 21:16:153 days 14 hrs ago0x1be6635ae9c30f8f8332b8f5d05e5abcbe214276 IN  0xaef876ee95d0feeaf5a5dedd4531cba074519beb0 MATIC0.000446725
0xa6fa429aa6106a959c5f73d4b87ab8d23090739a1426d609b89c87064fbf0764Safe Transfer Fr...191466452021-09-15 19:57:184 days 15 hrs ago0xce7bf1ac9e0baba188d1a297ad64bde16cf2967c IN  0xaef876ee95d0feeaf5a5dedd4531cba074519beb0 MATIC0.000727619933
0xb7ada577635496381cee2b0278d90ff85a97e77fa71f394695ceec4c6eab1dc3Forge191466242021-09-15 19:56:304 days 15 hrs ago0xce7bf1ac9e0baba188d1a297ad64bde16cf2967c IN  0xaef876ee95d0feeaf5a5dedd4531cba074519beb0 MATIC0.0059073
0xeaee1f3808ddc184213006c9d620f6f897a8b7563b8ae70edf2a683c3c543733Safe Transfer Fr...191460202021-09-15 19:30:284 days 16 hrs ago0xce7bf1ac9e0baba188d1a297ad64bde16cf2967c IN  0xaef876ee95d0feeaf5a5dedd4531cba074519beb0 MATIC0.0198487
0xd05b8aecca412194d279f4cf7ebf0b7434fb37d6abc44969a38d6fe6a9590dc1Forge191460192021-09-15 19:30:244 days 16 hrs ago0xce7bf1ac9e0baba188d1a297ad64bde16cf2967c IN  0xaef876ee95d0feeaf5a5dedd4531cba074519beb0 MATIC0.0053673
0x7e8e07ba544ae0e3c9caca32762988ddcd30c52693c600137d3869984d2a5965Safe Transfer Fr...191460172021-09-15 19:30:164 days 16 hrs ago0xce7bf1ac9e0baba188d1a297ad64bde16cf2967c IN  0xaef876ee95d0feeaf5a5dedd4531cba074519beb0 MATIC0.0198557
0x4c29d14926762cbcfadc408d7ef06a78c6468f34b0ddbafe2796a2fe67c9303dForge191460162021-09-15 19:30:124 days 16 hrs ago0xce7bf1ac9e0baba188d1a297ad64bde16cf2967c IN  0xaef876ee95d0feeaf5a5dedd4531cba074519beb0 MATIC0.0053673
0xb96c60489e4c22e8ceb863848f11167098dd9374e99d91b5ec1d12b667233264Safe Transfer Fr...191460142021-09-15 19:30:044 days 16 hrs ago0xce7bf1ac9e0baba188d1a297ad64bde16cf2967c IN  0xaef876ee95d0feeaf5a5dedd4531cba074519beb0 MATIC0.0169804
0xb305da14064e8072699f03f238e5822cc39bbc2782bfef5abd3f3ea91d113bd4Forge191460122021-09-15 19:29:564 days 16 hrs ago0xce7bf1ac9e0baba188d1a297ad64bde16cf2967c IN  0xaef876ee95d0feeaf5a5dedd4531cba074519beb0 MATIC0.0118146
0x32d1a63319ca4547cf62801c3cf577c11b24a580f3ec49a9e4607d5f632fc994Safe Transfer Fr...191460112021-09-15 19:29:524 days 16 hrs ago0xce7bf1ac9e0baba188d1a297ad64bde16cf2967c IN  0xaef876ee95d0feeaf5a5dedd4531cba074519beb0 MATIC0.0169804
0x57797585e5476fdc2a01712c694a3d7d1ecc2f62a85e55f9ed643941b160995dForge191460092021-09-15 19:29:444 days 16 hrs ago0xce7bf1ac9e0baba188d1a297ad64bde16cf2967c IN  0xaef876ee95d0feeaf5a5dedd4531cba074519beb0 MATIC0.0118146
0x52a3a3ab511ce0fa31dc704e12a4201085f68c6625524806a607e38316ae08a9Safe Transfer Fr...191460072021-09-15 19:29:364 days 16 hrs ago0xce7bf1ac9e0baba188d1a297ad64bde16cf2967c IN  0xaef876ee95d0feeaf5a5dedd4531cba074519beb0 MATIC0.0169804
0xb22327a80f479481778b5aa601297fdf1127ab8807d1546ff573b889986a3c18Forge191460052021-09-15 19:29:284 days 16 hrs ago0xce7bf1ac9e0baba188d1a297ad64bde16cf2967c IN  0xaef876ee95d0feeaf5a5dedd4531cba074519beb0 MATIC0.0118146
0x92f380b57ba1e521ec54def338ef01c257f02d0e0a427b9e4166cd720dd549f5Safe Transfer Fr...191460032021-09-15 19:29:204 days 16 hrs ago0xce7bf1ac9e0baba188d1a297ad64bde16cf2967c IN  0xaef876ee95d0feeaf5a5dedd4531cba074519beb0 MATIC0.0198487
0x3e71279f157af21b564981b32c040ef7fabe19c600b3460a5174d4a1e7cd35c3Forge191460022021-09-15 19:29:164 days 16 hrs ago0xce7bf1ac9e0baba188d1a297ad64bde16cf2967c IN  0xaef876ee95d0feeaf5a5dedd4531cba074519beb0 MATIC0.0053673
0xf5d818c5325f3e46162d9cb51318b2d8fb53e3d2491714081c3451c64dba941dSafe Transfer Fr...191460002021-09-15 19:29:084 days 16 hrs ago0xce7bf1ac9e0baba188d1a297ad64bde16cf2967c IN  0xaef876ee95d0feeaf5a5dedd4531cba074519beb0 MATIC0.0169804
0x1da52254d1052c76c85a51f864964c22e0761e0be8f7c1d2994132a9bf92404fForge191459982021-09-15 19:29:004 days 16 hrs ago0xce7bf1ac9e0baba188d1a297ad64bde16cf2967c IN  0xaef876ee95d0feeaf5a5dedd4531cba074519beb0 MATIC0.0118146
0xf0b6d132053b679c118a378559f5b3aad523a4ee2211070c0597ab9c4446766bSafe Transfer Fr...191459962021-09-15 19:28:524 days 16 hrs ago0xce7bf1ac9e0baba188d1a297ad64bde16cf2967c IN  0xaef876ee95d0feeaf5a5dedd4531cba074519beb0 MATIC0.0198487
0x67318756b8956daba70ac6a34d214fd79ada4fa82a4df4f75394ecc80952c7c3Forge191459942021-09-15 19:28:444 days 16 hrs ago0xce7bf1ac9e0baba188d1a297ad64bde16cf2967c IN  0xaef876ee95d0feeaf5a5dedd4531cba074519beb0 MATIC0.0053673
0xc6b84cb49bb1f86949451e67009fc97b698e813da811eb60d5d2c00250314f4fSafe Transfer Fr...191459922021-09-15 19:28:364 days 16 hrs ago0xce7bf1ac9e0baba188d1a297ad64bde16cf2967c IN  0xaef876ee95d0feeaf5a5dedd4531cba074519beb0 MATIC0.0169874
0xd5f207cefd79375256e103b08d7c28602068009de9191a0ab1ee92735854d13bForge191459902021-09-15 19:28:284 days 16 hrs ago0xce7bf1ac9e0baba188d1a297ad64bde16cf2967c IN  0xaef876ee95d0feeaf5a5dedd4531cba074519beb0 MATIC0.0118146
0x76febf87743c7ae7dc60c877a8586212d04d65e9505885898bdcd16e87389b34Safe Transfer Fr...191459882021-09-15 19:28:204 days 16 hrs ago0xce7bf1ac9e0baba188d1a297ad64bde16cf2967c IN  0xaef876ee95d0feeaf5a5dedd4531cba074519beb0 MATIC0.0169874
0xa38911a088e81f7fec34817c3d38027a0e097bb1d73d6eaf4c1b0bce027393edForge191459862021-09-15 19:28:124 days 16 hrs ago0xce7bf1ac9e0baba188d1a297ad64bde16cf2967c IN  0xaef876ee95d0feeaf5a5dedd4531cba074519beb0 MATIC0.0118146
0x73442f06a85421ca972e15d58185c4adc64528d4237dd83da4209b56f17d479cSafe Transfer Fr...191459842021-09-15 19:28:044 days 16 hrs ago0xce7bf1ac9e0baba188d1a297ad64bde16cf2967c IN  0xaef876ee95d0feeaf5a5dedd4531cba074519beb0 MATIC0.0198487
[ Download CSV Export 
Parent Txn Hash Block From To Value
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
Assets

Compiler Version
v0.7.4+commit.3f05b770

Optimization Enabled:
Yes with 1 runs

Other Settings:
istanbul EvmVersion, MIT license

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 59 : Assets.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.4;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/utils/EnumerableSet.sol";

import "./meta/EIP712MetaTransaction.sol";
import "./interfaces/IRegisterableAsset.sol";
import "./interfaces/IAssets.sol";
import "./Constants.sol";

import "hardhat/console.sol";

contract Assets is IAssets, ERC1155, Ownable, EIP712MetaTransaction {
  using SafeMath for uint256;
  using EnumerableSet for EnumerableSet.UintSet;

  uint8 constant internal _vers = 1;

  IAssets immutable public deprecatedAssets; 

  bytes32[] private _assetNames;
  uint256[] private _minIDs;

  // registry containing fungible / non-fungible tokens
  // fungible tokens have minID == totalSupply
  // nfts have a range of IDs, specified via totalSupply 
  struct AssetType {
    bool    isNFT;
    uint256 minID;
    uint256 totalSupply;
    uint256 currentSupply;
    mapping (address => bool) operators;
  }
  
  mapping(bytes32 => AssetType) private _assets;

  mapping (address => EnumerableSet.UintSet) private _accountTokens;

  constructor(address oldAssets) public ERC1155("/1155/{id}.json") EIP712MetaTransaction("Assets", "1")  {
    deprecatedAssets = IAssets(oldAssets);
  }

  function register(
    bytes32 name,
    bool    isNFT,
    uint256 totalSupply,
    address[] memory operators
  ) public onlyOwner {
    require(totalSupply > 0, "total supply must be greater than 0");

    uint256 minID;
    if (_assetNames.length == 0) {
      minID = 0;
    } else {
      require(_assets[name].totalSupply == 0, "asset name already taken");
      // get maxID of last asset, and add 1
      minID = _maxID(_assets[_assetNames[_assetNames.length - 1]]) + 1;
    }

    AssetType storage asset = _assets[name];
    asset.isNFT = isNFT;
    asset.minID = minID;
    asset.totalSupply = totalSupply;
    asset.currentSupply = 0;

    for (uint i = 0; i < operators.length; i++) {
      asset.operators[operators[i]] = true;
    }
    if (operators.length == 0) {
      asset.operators[msgSender()] = true;
    }

    require(_maxID(asset) < type(uint256).max, "out of ids");

    _assetNames.push(name);
    _minIDs.push(minID);
  }

  function registerAssetContract(
    address contractAddress
  ) public onlyOwner {
    IRegisterableAsset asset = IRegisterableAsset(contractAddress);
    register(
      asset.assetName(),
      asset.assetIsNFT(),
      asset.assetTotalSupply(),
      asset.assetOperators()
    );
  }

  function addOperator(address operator_, bytes32 name) external returns (bool) {
    AssetType storage asset = _assets[name];
    require(asset.operators[msgSender()], "Assets: Not authorized to add");
    asset.operators[operator_] = true;
    return true;
  }

  function removeOperator(address operator_, bytes32 name) external returns (bool) {
    AssetType storage asset = _assets[name];
    require(asset.operators[msgSender()], "Assets: Not authorized to add");
    delete asset.operators[operator_];
    return true;
  }

  function mint(
    address account,
    bytes32 name,
    uint256 amount,
    bytes memory data
  ) override external returns(uint256[] memory) {
    AssetType storage asset = _assets[name];
    require(asset.operators[msgSender()], "Assets: Not authorized to mint");
    require((asset.currentSupply + amount) <= asset.totalSupply, "Assets: Token supply exhausted");

    uint256[] memory mintedIDs;

    if (asset.isNFT) {
      mintedIDs = new uint256[](amount);
      for (uint i; i < amount; i++) {
        _mint(account, asset.minID + asset.currentSupply + i, 1, data);
        mintedIDs[i] = asset.minID + asset.currentSupply + i;
      }
    } else {
      mintedIDs = new uint256[](1);
      mintedIDs[0] = asset.minID;
      _mint(account, asset.minID, amount, data);
    }

    asset.currentSupply = asset.currentSupply + amount;
    return mintedIDs;
  }

  /**
  This function is for assets like equipment where it's kind of an NFT and kind of a fungible
  ie: it's an NFT (there's only 1 contract), but there can be more than one of a type
  something like "5 swords" but we don't want to deploy a new contract per Equipment 
  */
  function forge(
    address account,
    uint id,
    uint amount,
    bytes memory data
  ) override external returns (bool) {
    bytes32 name = nameForID(id);
    AssetType storage asset = _assets[name];
    require(asset.operators[msgSender()], "Assets: Not authorized to forge");
    _mint(account, id, amount, data);
    return true;
  }
  
  function burn(
    address account,
    bytes32 name,
    uint256 amount
  ) override external {
    AssetType storage asset = _assets[name];
    require(asset.isNFT == false, "cannot burn NFTs");
    require(
      isApprovedOrOwner(account, msgSender(), asset.minID),
      "Assets: caller is not owner nor approved"
    );
    _burn(account, asset.minID, amount);
    asset.currentSupply = asset.currentSupply - amount;
  }

  function isOwner(
    address account,
    uint256 id
  ) override public view returns (bool) {
    return balanceOf(account, id) > 0;
  }

  function isApprovedOrOwner(
    address account,
    address operator,
    uint256 id
  ) override public view returns (bool) {
    return isApprovedForAll(account, operator) || ( account == operator && isOwner(account, id) );
  }

  // given an ID inside a minted range, return the type name
  function nameForID(
    uint256 id
  ) override public view returns (bytes32) {
    uint256 lastIndex = _minIDs.length - 1;
    for (uint256 i = 0; i <= lastIndex; i++) {
      if (i == lastIndex) {
        AssetType storage lastAsset = _assets[_assetNames[i]];
        if (id <= _maxID(lastAsset)) {
          return _assetNames[i];
        }
      } else if(_minIDs[i] <= id && id < _minIDs[i + 1]) {
        return _assetNames[i];
      }
    }
  }

  function idRange(
    bytes32 name
  ) override public view returns (uint256, uint256) {
    AssetType storage asset = _assets[name];
    if (asset.isNFT) {
      return (asset.minID, asset.minID + asset.totalSupply - 1);
    }
    return (asset.minID, asset.minID);
  }

  // has the token of name been minted
  function exists(
    bytes32 name,
    uint256 id
  ) override public view returns (bool) {
    AssetType storage asset = _assets[name];
    if (!asset.isNFT) {
      return asset.minID == id && asset.currentSupply > 0;
    }
    return asset.minID <= id && id < (asset.minID + asset.currentSupply);
  }

  function totalSupply(
    bytes32 name
  ) override external view returns (uint256) {
    return _assets[name].totalSupply;
  }

  function currentSupply(
    bytes32 name
  ) override external view returns (uint256) {
    return _assets[name].currentSupply;
  }

  function accountTokens(
    address account
  ) override public view returns (uint256[] memory) {
    uint256 tokenCount = _accountTokens[account].length(); 
    uint256[] memory ids = new uint256[](tokenCount);
    for (uint256 i = 0; i < tokenCount; i++) {
      ids[i] = _accountTokens[account].at(i);
    }
    return ids;
  }

  function _msgSender() internal view override(Context,EIP712MetaTransaction) returns (address payable) {
    return EIP712MetaTransaction.msgSender();
  }

  function _maxID(
    AssetType storage asset
  ) internal view returns(uint256) {
    if (asset.isNFT == false) {
      return asset.minID;
    }
    return asset.minID + asset.totalSupply - 1;
  }

  function _beforeTokenTransfer(
    address,
    address from,
    address to,
    uint256[] memory ids,
    uint256[] memory amounts,
    bytes memory
  ) internal override {
    for (uint256 i = 0; i < ids.length; i++) {
      if (from != address(0) && (balanceOf(from, ids[i]) - amounts[i]) <= 0) {
        _accountTokens[from].remove(ids[i]);
      }
      if (to != address(0)) {
        _accountTokens[to].add(ids[i]);
      }
    }
  }

  function onERC1155Received(
    address,
    address from,
    uint256 id,
    uint256 value,
    bytes calldata
  ) external returns(bytes4) {
    require(msg.sender == address(deprecatedAssets), "Assets#onERC1155Received: invalid old asset address");
    (uint prestigeStart, uint prestigeEnd) = deprecatedAssets.idRange(Constants.PRESTIGE_ASSET_NAME);
    require(id >= prestigeStart && id <= prestigeEnd, "Assets#Only supports prestige migration");
    
    AssetType storage prestige = _assets[Constants.PRESTIGE_ASSET_NAME];

    _mint(from, prestige.minID, value, '');
    
    return IERC1155Receiver.onERC1155Received.selector;
  }
}

File 2 of 59 : SafeMath.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

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

        return c;
    }

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

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

        return c;
    }

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

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

        return c;
    }

    /**
     * @dev Returns the integer division of two unsigned integers. Reverts on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        return div(a, b, "SafeMath: division by zero");
    }

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

        return c;
    }

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

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

File 3 of 59 : Ownable.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "../GSN/Context.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 Ownable is Context {
    address private _owner;

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

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor () internal {
        address msgSender = _msgSender();
        _owner = msgSender;
        emit OwnershipTransferred(address(0), msgSender);
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view 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 {
        emit OwnershipTransferred(_owner, address(0));
        _owner = 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");
        emit OwnershipTransferred(_owner, newOwner);
        _owner = newOwner;
    }
}

File 4 of 59 : ERC1155.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "./IERC1155.sol";
import "./IERC1155MetadataURI.sol";
import "./IERC1155Receiver.sol";
import "../../GSN/Context.sol";
import "../../introspection/ERC165.sol";
import "../../math/SafeMath.sol";
import "../../utils/Address.sol";

/**
 *
 * @dev Implementation of the basic standard multi-token.
 * See https://eips.ethereum.org/EIPS/eip-1155
 * Originally based on code by Enjin: https://github.com/enjin/erc-1155
 *
 * _Available since v3.1._
 */
contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
    using SafeMath for uint256;
    using Address for address;

    // Mapping from token ID to account balances
    mapping (uint256 => mapping(address => uint256)) private _balances;

    // Mapping from account to operator approvals
    mapping (address => mapping(address => bool)) private _operatorApprovals;

    // Used as the URI for all token types by relying on ID substitution, e.g. https://token-cdn-domain/{id}.json
    string private _uri;

    /*
     *     bytes4(keccak256('balanceOf(address,uint256)')) == 0x00fdd58e
     *     bytes4(keccak256('balanceOfBatch(address[],uint256[])')) == 0x4e1273f4
     *     bytes4(keccak256('setApprovalForAll(address,bool)')) == 0xa22cb465
     *     bytes4(keccak256('isApprovedForAll(address,address)')) == 0xe985e9c5
     *     bytes4(keccak256('safeTransferFrom(address,address,uint256,uint256,bytes)')) == 0xf242432a
     *     bytes4(keccak256('safeBatchTransferFrom(address,address,uint256[],uint256[],bytes)')) == 0x2eb2c2d6
     *
     *     => 0x00fdd58e ^ 0x4e1273f4 ^ 0xa22cb465 ^
     *        0xe985e9c5 ^ 0xf242432a ^ 0x2eb2c2d6 == 0xd9b67a26
     */
    bytes4 private constant _INTERFACE_ID_ERC1155 = 0xd9b67a26;

    /*
     *     bytes4(keccak256('uri(uint256)')) == 0x0e89341c
     */
    bytes4 private constant _INTERFACE_ID_ERC1155_METADATA_URI = 0x0e89341c;

    /**
     * @dev See {_setURI}.
     */
    constructor (string memory uri_) public {
        _setURI(uri_);

        // register the supported interfaces to conform to ERC1155 via ERC165
        _registerInterface(_INTERFACE_ID_ERC1155);

        // register the supported interfaces to conform to ERC1155MetadataURI via ERC165
        _registerInterface(_INTERFACE_ID_ERC1155_METADATA_URI);
    }

    /**
     * @dev See {IERC1155MetadataURI-uri}.
     *
     * This implementation returns the same URI for *all* token types. It relies
     * on the token type ID substitution mechanism
     * https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP].
     *
     * Clients calling this function must replace the `\{id\}` substring with the
     * actual token type ID.
     */
    function uri(uint256) external view override returns (string memory) {
        return _uri;
    }

    /**
     * @dev See {IERC1155-balanceOf}.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     */
    function balanceOf(address account, uint256 id) public view override returns (uint256) {
        require(account != address(0), "ERC1155: balance query for the zero address");
        return _balances[id][account];
    }

    /**
     * @dev See {IERC1155-balanceOfBatch}.
     *
     * Requirements:
     *
     * - `accounts` and `ids` must have the same length.
     */
    function balanceOfBatch(
        address[] memory accounts,
        uint256[] memory ids
    )
        public
        view
        override
        returns (uint256[] memory)
    {
        require(accounts.length == ids.length, "ERC1155: accounts and ids length mismatch");

        uint256[] memory batchBalances = new uint256[](accounts.length);

        for (uint256 i = 0; i < accounts.length; ++i) {
            require(accounts[i] != address(0), "ERC1155: batch balance query for the zero address");
            batchBalances[i] = _balances[ids[i]][accounts[i]];
        }

        return batchBalances;
    }

    /**
     * @dev See {IERC1155-setApprovalForAll}.
     */
    function setApprovalForAll(address operator, bool approved) public virtual override {
        require(_msgSender() != operator, "ERC1155: setting approval status for self");

        _operatorApprovals[_msgSender()][operator] = approved;
        emit ApprovalForAll(_msgSender(), operator, approved);
    }

    /**
     * @dev See {IERC1155-isApprovedForAll}.
     */
    function isApprovedForAll(address account, address operator) public view override returns (bool) {
        return _operatorApprovals[account][operator];
    }

    /**
     * @dev See {IERC1155-safeTransferFrom}.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 id,
        uint256 amount,
        bytes memory data
    )
        public
        virtual
        override
    {
        require(to != address(0), "ERC1155: transfer to the zero address");
        require(
            from == _msgSender() || isApprovedForAll(from, _msgSender()),
            "ERC1155: caller is not owner nor approved"
        );

        address operator = _msgSender();

        _beforeTokenTransfer(operator, from, to, _asSingletonArray(id), _asSingletonArray(amount), data);

        _balances[id][from] = _balances[id][from].sub(amount, "ERC1155: insufficient balance for transfer");
        _balances[id][to] = _balances[id][to].add(amount);

        emit TransferSingle(operator, from, to, id, amount);

        _doSafeTransferAcceptanceCheck(operator, from, to, id, amount, data);
    }

    /**
     * @dev See {IERC1155-safeBatchTransferFrom}.
     */
    function safeBatchTransferFrom(
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    )
        public
        virtual
        override
    {
        require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
        require(to != address(0), "ERC1155: transfer to the zero address");
        require(
            from == _msgSender() || isApprovedForAll(from, _msgSender()),
            "ERC1155: transfer caller is not owner nor approved"
        );

        address operator = _msgSender();

        _beforeTokenTransfer(operator, from, to, ids, amounts, data);

        for (uint256 i = 0; i < ids.length; ++i) {
            uint256 id = ids[i];
            uint256 amount = amounts[i];

            _balances[id][from] = _balances[id][from].sub(
                amount,
                "ERC1155: insufficient balance for transfer"
            );
            _balances[id][to] = _balances[id][to].add(amount);
        }

        emit TransferBatch(operator, from, to, ids, amounts);

        _doSafeBatchTransferAcceptanceCheck(operator, from, to, ids, amounts, data);
    }

    /**
     * @dev Sets a new URI for all token types, by relying on the token type ID
     * substitution mechanism
     * https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP].
     *
     * By this mechanism, any occurrence of the `\{id\}` substring in either the
     * URI or any of the amounts in the JSON file at said URI will be replaced by
     * clients with the token type ID.
     *
     * For example, the `https://token-cdn-domain/\{id\}.json` URI would be
     * interpreted by clients as
     * `https://token-cdn-domain/000000000000000000000000000000000000000000000000000000000004cce0.json`
     * for token type ID 0x4cce0.
     *
     * See {uri}.
     *
     * Because these URIs cannot be meaningfully represented by the {URI} event,
     * this function emits no events.
     */
    function _setURI(string memory newuri) internal virtual {
        _uri = newuri;
    }

    /**
     * @dev Creates `amount` tokens of token type `id`, and assigns them to `account`.
     *
     * Emits a {TransferSingle} event.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
     * acceptance magic value.
     */
    function _mint(address account, uint256 id, uint256 amount, bytes memory data) internal virtual {
        require(account != address(0), "ERC1155: mint to the zero address");

        address operator = _msgSender();

        _beforeTokenTransfer(operator, address(0), account, _asSingletonArray(id), _asSingletonArray(amount), data);

        _balances[id][account] = _balances[id][account].add(amount);
        emit TransferSingle(operator, address(0), account, id, amount);

        _doSafeTransferAcceptanceCheck(operator, address(0), account, id, amount, data);
    }

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_mint}.
     *
     * 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 _mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data) internal virtual {
        require(to != address(0), "ERC1155: mint to the zero address");
        require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");

        address operator = _msgSender();

        _beforeTokenTransfer(operator, address(0), to, ids, amounts, data);

        for (uint i = 0; i < ids.length; i++) {
            _balances[ids[i]][to] = amounts[i].add(_balances[ids[i]][to]);
        }

        emit TransferBatch(operator, address(0), to, ids, amounts);

        _doSafeBatchTransferAcceptanceCheck(operator, address(0), to, ids, amounts, data);
    }

    /**
     * @dev Destroys `amount` tokens of token type `id` from `account`
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     * - `account` must have at least `amount` tokens of token type `id`.
     */
    function _burn(address account, uint256 id, uint256 amount) internal virtual {
        require(account != address(0), "ERC1155: burn from the zero address");

        address operator = _msgSender();

        _beforeTokenTransfer(operator, account, address(0), _asSingletonArray(id), _asSingletonArray(amount), "");

        _balances[id][account] = _balances[id][account].sub(
            amount,
            "ERC1155: burn amount exceeds balance"
        );

        emit TransferSingle(operator, account, address(0), id, amount);
    }

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_burn}.
     *
     * Requirements:
     *
     * - `ids` and `amounts` must have the same length.
     */
    function _burnBatch(address account, uint256[] memory ids, uint256[] memory amounts) internal virtual {
        require(account != address(0), "ERC1155: burn from the zero address");
        require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");

        address operator = _msgSender();

        _beforeTokenTransfer(operator, account, address(0), ids, amounts, "");

        for (uint i = 0; i < ids.length; i++) {
            _balances[ids[i]][account] = _balances[ids[i]][account].sub(
                amounts[i],
                "ERC1155: burn amount exceeds balance"
            );
        }

        emit TransferBatch(operator, account, address(0), ids, amounts);
    }

    /**
     * @dev Hook that is called before any token transfer. This includes minting
     * and burning, as well as batched variants.
     *
     * The same hook is called on both single and batched variants. For single
     * transfers, the length of the `id` and `amount` arrays will be 1.
     *
     * Calling conditions (for each `id` and `amount` pair):
     *
     * - When `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * of token type `id` will be  transferred to `to`.
     * - When `from` is zero, `amount` tokens of token type `id` will be minted
     * for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens of token type `id`
     * will be burned.
     * - `from` and `to` are never both zero.
     * - `ids` and `amounts` have the same, non-zero length.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(
        address operator,
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    )
        internal virtual
    { }

    function _doSafeTransferAcceptanceCheck(
        address operator,
        address from,
        address to,
        uint256 id,
        uint256 amount,
        bytes memory data
    )
        private
    {
        if (to.isContract()) {
            try IERC1155Receiver(to).onERC1155Received(operator, from, id, amount, data) returns (bytes4 response) {
                if (response != IERC1155Receiver(to).onERC1155Received.selector) {
                    revert("ERC1155: ERC1155Receiver rejected tokens");
                }
            } catch Error(string memory reason) {
                revert(reason);
            } catch {
                revert("ERC1155: transfer to non ERC1155Receiver implementer");
            }
        }
    }

    function _doSafeBatchTransferAcceptanceCheck(
        address operator,
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    )
        private
    {
        if (to.isContract()) {
            try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, amounts, data) returns (bytes4 response) {
                if (response != IERC1155Receiver(to).onERC1155BatchReceived.selector) {
                    revert("ERC1155: ERC1155Receiver rejected tokens");
                }
            } catch Error(string memory reason) {
                revert(reason);
            } catch {
                revert("ERC1155: transfer to non ERC1155Receiver implementer");
            }
        }
    }

    function _asSingletonArray(uint256 element) private pure returns (uint256[] memory) {
        uint256[] memory array = new uint256[](1);
        array[0] = element;

        return array;
    }
}

File 5 of 59 : EnumerableSet.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <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 EnumerableSet {
    // 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;

            // When the value to delete is the last one, the swap operation is unnecessary. However, since this occurs
            // so rarely, we still do the swap anyway to avoid the gas cost of adding an 'if' statement.

            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] = toDeleteIndex + 1; // All indexes are 1-based

            // 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) {
        require(set._values.length > index, "EnumerableSet: index out of bounds");
        return set._values[index];
    }

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

    // 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(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(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(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(uint256(_at(set._inner, index)));
    }


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

File 6 of 59 : EIP712MetaTransaction.sol
// imported from https://github.com/bcnmy/metatx-standard/blob/8a6564b8fac5d2aceebb1972bcffdd5e88ceec63/src/contracts/EIP712MetaTransaction.sol
// modified to support solidity 0.7
pragma solidity 0.7.4;

import "./EIP712Base.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "hardhat/console.sol";

contract EIP712MetaTransaction is EIP712Base {
    using SafeMath for uint256;
    bytes32 private constant META_TRANSACTION_TYPEHASH = keccak256(bytes("MetaTransaction(uint256 nonce,address from,bytes functionSignature)"));

    event MetaTransactionExecuted(address userAddress, address payable relayerAddress, bytes functionSignature);
    mapping(address => uint256) private nonces;

    /*
     * Meta transaction structure.
     * No point of including value field here as if user is doing value transfer then he has the funds to pay for gas
     * He should call the desired function directly in that case.
     */
    struct MetaTransaction {
        uint256 nonce;
        address from;
        bytes functionSignature;
    }

    constructor(string memory name, string memory version) public EIP712Base(name, version) {}

    function convertBytesToBytes4(bytes memory inBytes) internal pure returns (bytes4 outBytes4) {
        if (inBytes.length == 0) {
            return 0x0;
        }

        assembly {
            outBytes4 := mload(add(inBytes, 32))
        }
    }

    function executeMetaTransaction(address userAddress,
        bytes memory functionSignature, bytes32 sigR, bytes32 sigS, uint8 sigV) public payable returns(bytes memory) {
        bytes4 destinationFunctionSig = convertBytesToBytes4(functionSignature);
        require(destinationFunctionSig != msg.sig, "functionSignature can not be of executeMetaTransaction method");
        MetaTransaction memory metaTx = MetaTransaction({
            nonce: nonces[userAddress],
            from: userAddress,
            functionSignature: functionSignature
        });
        require(verify(userAddress, metaTx, sigR, sigS, sigV), "Signer and signature do not match");
        nonces[userAddress] = nonces[userAddress].add(1);
        // Append userAddress at the end to extract it from calling context
        (bool success, bytes memory returnData) = address(this).call(abi.encodePacked(functionSignature, userAddress));

        require(success, "Function call not successful");
        emit MetaTransactionExecuted(userAddress, msg.sender, functionSignature);
        return returnData;
    }

    function hashMetaTransaction(MetaTransaction memory metaTx) internal pure returns (bytes32) {
        return keccak256(abi.encode(
            META_TRANSACTION_TYPEHASH,
            metaTx.nonce,
            metaTx.from,
            keccak256(metaTx.functionSignature)
        ));
    }

    function getNonce(address user) external view returns(uint256 nonce) {
        nonce = nonces[user];
    }

    function verify(address user, MetaTransaction memory metaTx, bytes32 sigR, bytes32 sigS, uint8 sigV) internal view returns (bool) {
        address signer = ecrecover(toTypedMessageHash(hashMetaTransaction(metaTx)), sigV, sigR, sigS);
        require(signer != address(0), "Invalid signature");
        return signer == user;
    }

    function _msgSender() internal view virtual returns (address payable) {
        return msgSender();
    }

    function msgSender() internal view returns(address payable sender) {
        if(msg.sender == address(this)) {
            bytes memory array = msg.data;
            uint256 index = msg.data.length;
            assembly {
                // Load the 32 bytes word from memory with the address on the lower 20 bytes, and mask those.
                sender := and(mload(add(array, index)), 0xffffffffffffffffffffffffffffffffffffffff)
            }
        } else {
            sender = msg.sender;
        }
        return sender;
    }
}

File 7 of 59 : IRegisterableAsset.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.4;

interface IRegisterableAsset {
  function assetName() external view returns (bytes32);
  function assetTotalSupply() external pure returns (uint256);
  function assetIsNFT() external pure returns (bool);
  function assetOperators() external view returns (address[] memory);
}

File 8 of 59 : IAssets.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.4;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";

interface IAssets is IERC1155 {
  function mint(
    address account,
    bytes32 name,
    uint256 amount,
    bytes memory data
  ) external returns(uint256[] memory);
  
  function forge(
    address account,
    uint id,
    uint amount,
    bytes memory data
  ) external returns (bool);

  function burn(
    address account,
    bytes32 name,
    uint256 amount
  ) external;

  function isOwner(
    address account,
    uint256 id
  ) external view returns(bool);

  function isApprovedOrOwner(
    address account,
    address operator,
    uint256 id
  ) external view returns(bool);

  function nameForID(
    uint256 id
  ) external view returns(bytes32);

  function idRange(
    bytes32 name
  ) external view returns (uint256, uint256);

  function exists(
    bytes32 name,
    uint256 id
  ) external view returns (bool);

  function totalSupply(
    bytes32 name
  ) external view returns (uint256);

  function currentSupply(
    bytes32 name
  ) external view returns (uint256);

  function accountTokens(
    address account
  ) external view returns (uint256[] memory);
}

File 9 of 59 : Constants.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.4;

library Constants {
  bytes32 constant PRESTIGE_ASSET_NAME = "prestige";

  function prestigeAssetName() internal pure returns(bytes32){
    return PRESTIGE_ASSET_NAME;
  }
}

File 10 of 59 : console.sol
// SPDX-License-Identifier: MIT
pragma solidity >= 0.4.22 <0.9.0;

library console {
	address constant CONSOLE_ADDRESS = address(0x000000000000000000636F6e736F6c652e6c6f67);

	function _sendLogPayload(bytes memory payload) private view {
		uint256 payloadLength = payload.length;
		address consoleAddress = CONSOLE_ADDRESS;
		assembly {
			let payloadStart := add(payload, 32)
			let r := staticcall(gas(), consoleAddress, payloadStart, payloadLength, 0, 0)
		}
	}

	function log() internal view {
		_sendLogPayload(abi.encodeWithSignature("log()"));
	}

	function logInt(int p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(int)", p0));
	}

	function logUint(uint p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint)", p0));
	}

	function logString(string memory p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string)", p0));
	}

	function logBool(bool p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool)", p0));
	}

	function logAddress(address p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address)", p0));
	}

	function logBytes(bytes memory p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes)", p0));
	}

	function logBytes1(bytes1 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes1)", p0));
	}

	function logBytes2(bytes2 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes2)", p0));
	}

	function logBytes3(bytes3 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes3)", p0));
	}

	function logBytes4(bytes4 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes4)", p0));
	}

	function logBytes5(bytes5 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes5)", p0));
	}

	function logBytes6(bytes6 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes6)", p0));
	}

	function logBytes7(bytes7 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes7)", p0));
	}

	function logBytes8(bytes8 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes8)", p0));
	}

	function logBytes9(bytes9 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes9)", p0));
	}

	function logBytes10(bytes10 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes10)", p0));
	}

	function logBytes11(bytes11 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes11)", p0));
	}

	function logBytes12(bytes12 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes12)", p0));
	}

	function logBytes13(bytes13 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes13)", p0));
	}

	function logBytes14(bytes14 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes14)", p0));
	}

	function logBytes15(bytes15 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes15)", p0));
	}

	function logBytes16(bytes16 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes16)", p0));
	}

	function logBytes17(bytes17 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes17)", p0));
	}

	function logBytes18(bytes18 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes18)", p0));
	}

	function logBytes19(bytes19 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes19)", p0));
	}

	function logBytes20(bytes20 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes20)", p0));
	}

	function logBytes21(bytes21 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes21)", p0));
	}

	function logBytes22(bytes22 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes22)", p0));
	}

	function logBytes23(bytes23 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes23)", p0));
	}

	function logBytes24(bytes24 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes24)", p0));
	}

	function logBytes25(bytes25 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes25)", p0));
	}

	function logBytes26(bytes26 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes26)", p0));
	}

	function logBytes27(bytes27 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes27)", p0));
	}

	function logBytes28(bytes28 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes28)", p0));
	}

	function logBytes29(bytes29 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes29)", p0));
	}

	function logBytes30(bytes30 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes30)", p0));
	}

	function logBytes31(bytes31 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes31)", p0));
	}

	function logBytes32(bytes32 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes32)", p0));
	}

	function log(uint p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint)", p0));
	}

	function log(string memory p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string)", p0));
	}

	function log(bool p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool)", p0));
	}

	function log(address p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address)", p0));
	}

	function log(uint p0, uint p1) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,uint)", p0, p1));
	}

	function log(uint p0, string memory p1) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,string)", p0, p1));
	}

	function log(uint p0, bool p1) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,bool)", p0, p1));
	}

	function log(uint p0, address p1) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,address)", p0, p1));
	}

	function log(string memory p0, uint p1) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint)", p0, p1));
	}

	function log(string memory p0, string memory p1) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string)", p0, p1));
	}

	function log(string memory p0, bool p1) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool)", p0, p1));
	}

	function log(string memory p0, address p1) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address)", p0, p1));
	}

	function log(bool p0, uint p1) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint)", p0, p1));
	}

	function log(bool p0, string memory p1) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string)", p0, p1));
	}

	function log(bool p0, bool p1) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool)", p0, p1));
	}

	function log(bool p0, address p1) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address)", p0, p1));
	}

	function log(address p0, uint p1) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint)", p0, p1));
	}

	function log(address p0, string memory p1) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string)", p0, p1));
	}

	function log(address p0, bool p1) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool)", p0, p1));
	}

	function log(address p0, address p1) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address)", p0, p1));
	}

	function log(uint p0, uint p1, uint p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint)", p0, p1, p2));
	}

	function log(uint p0, uint p1, string memory p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,uint,string)", p0, p1, p2));
	}

	function log(uint p0, uint p1, bool p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,uint,bool)", p0, p1, p2));
	}

	function log(uint p0, uint p1, address p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,uint,address)", p0, p1, p2));
	}

	function log(uint p0, string memory p1, uint p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,string,uint)", p0, p1, p2));
	}

	function log(uint p0, string memory p1, string memory p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,string,string)", p0, p1, p2));
	}

	function log(uint p0, string memory p1, bool p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,string,bool)", p0, p1, p2));
	}

	function log(uint p0, string memory p1, address p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,string,address)", p0, p1, p2));
	}

	function log(uint p0, bool p1, uint p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,bool,uint)", p0, p1, p2));
	}

	function log(uint p0, bool p1, string memory p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,bool,string)", p0, p1, p2));
	}

	function log(uint p0, bool p1, bool p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,bool,bool)", p0, p1, p2));
	}

	function log(uint p0, bool p1, address p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,bool,address)", p0, p1, p2));
	}

	function log(uint p0, address p1, uint p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,address,uint)", p0, p1, p2));
	}

	function log(uint p0, address p1, string memory p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,address,string)", p0, p1, p2));
	}

	function log(uint p0, address p1, bool p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,address,bool)", p0, p1, p2));
	}

	function log(uint p0, address p1, address p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,address,address)", p0, p1, p2));
	}

	function log(string memory p0, uint p1, uint p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint,uint)", p0, p1, p2));
	}

	function log(string memory p0, uint p1, string memory p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint,string)", p0, p1, p2));
	}

	function log(string memory p0, uint p1, bool p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint,bool)", p0, p1, p2));
	}

	function log(string memory p0, uint p1, address p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint,address)", p0, p1, p2));
	}

	function log(string memory p0, string memory p1, uint p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string,uint)", p0, p1, p2));
	}

	function log(string memory p0, string memory p1, string memory p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string,string)", p0, p1, p2));
	}

	function log(string memory p0, string memory p1, bool p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string,bool)", p0, p1, p2));
	}

	function log(string memory p0, string memory p1, address p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string,address)", p0, p1, p2));
	}

	function log(string memory p0, bool p1, uint p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint)", p0, p1, p2));
	}

	function log(string memory p0, bool p1, string memory p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool,string)", p0, p1, p2));
	}

	function log(string memory p0, bool p1, bool p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool)", p0, p1, p2));
	}

	function log(string memory p0, bool p1, address p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool,address)", p0, p1, p2));
	}

	function log(string memory p0, address p1, uint p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address,uint)", p0, p1, p2));
	}

	function log(string memory p0, address p1, string memory p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address,string)", p0, p1, p2));
	}

	function log(string memory p0, address p1, bool p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address,bool)", p0, p1, p2));
	}

	function log(string memory p0, address p1, address p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address,address)", p0, p1, p2));
	}

	function log(bool p0, uint p1, uint p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint,uint)", p0, p1, p2));
	}

	function log(bool p0, uint p1, string memory p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint,string)", p0, p1, p2));
	}

	function log(bool p0, uint p1, bool p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint,bool)", p0, p1, p2));
	}

	function log(bool p0, uint p1, address p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint,address)", p0, p1, p2));
	}

	function log(bool p0, string memory p1, uint p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint)", p0, p1, p2));
	}

	function log(bool p0, string memory p1, string memory p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string,string)", p0, p1, p2));
	}

	function log(bool p0, string memory p1, bool p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool)", p0, p1, p2));
	}

	function log(bool p0, string memory p1, address p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string,address)", p0, p1, p2));
	}

	function log(bool p0, bool p1, uint p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint)", p0, p1, p2));
	}

	function log(bool p0, bool p1, string memory p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool,string)", p0, p1, p2));
	}

	function log(bool p0, bool p1, bool p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool)", p0, p1, p2));
	}

	function log(bool p0, bool p1, address p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool,address)", p0, p1, p2));
	}

	function log(bool p0, address p1, uint p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address,uint)", p0, p1, p2));
	}

	function log(bool p0, address p1, string memory p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address,string)", p0, p1, p2));
	}

	function log(bool p0, address p1, bool p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address,bool)", p0, p1, p2));
	}

	function log(bool p0, address p1, address p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address,address)", p0, p1, p2));
	}

	function log(address p0, uint p1, uint p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint,uint)", p0, p1, p2));
	}

	function log(address p0, uint p1, string memory p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint,string)", p0, p1, p2));
	}

	function log(address p0, uint p1, bool p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint,bool)", p0, p1, p2));
	}

	function log(address p0, uint p1, address p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint,address)", p0, p1, p2));
	}

	function log(address p0, string memory p1, uint p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string,uint)", p0, p1, p2));
	}

	function log(address p0, string memory p1, string memory p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string,string)", p0, p1, p2));
	}

	function log(address p0, string memory p1, bool p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string,bool)", p0, p1, p2));
	}

	function log(address p0, string memory p1, address p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string,address)", p0, p1, p2));
	}

	function log(address p0, bool p1, uint p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool,uint)", p0, p1, p2));
	}

	function log(address p0, bool p1, string memory p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool,string)", p0, p1, p2));
	}

	function log(address p0, bool p1, bool p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool,bool)", p0, p1, p2));
	}

	function log(address p0, bool p1, address p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool,address)", p0, p1, p2));
	}

	function log(address p0, address p1, uint p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address,uint)", p0, p1, p2));
	}

	function log(address p0, address p1, string memory p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address,string)", p0, p1, p2));
	}

	function log(address p0, address p1, bool p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address,bool)", p0, p1, p2));
	}

	function log(address p0, address p1, address p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address,address)", p0, p1, p2));
	}

	function log(uint p0, uint p1, uint p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint,uint)", p0, p1, p2, p3));
	}

	function log(uint p0, uint p1, uint p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint,string)", p0, p1, p2, p3));
	}

	function log(uint p0, uint p1, uint p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint,bool)", p0, p1, p2, p3));
	}

	function log(uint p0, uint p1, uint p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint,address)", p0, p1, p2, p3));
	}

	function log(uint p0, uint p1, string memory p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,uint,string,uint)", p0, p1, p2, p3));
	}

	function log(uint p0, uint p1, string memory p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,uint,string,string)", p0, p1, p2, p3));
	}

	function log(uint p0, uint p1, string memory p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,uint,string,bool)", p0, p1, p2, p3));
	}

	function log(uint p0, uint p1, string memory p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,uint,string,address)", p0, p1, p2, p3));
	}

	function log(uint p0, uint p1, bool p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,uint,bool,uint)", p0, p1, p2, p3));
	}

	function log(uint p0, uint p1, bool p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,uint,bool,string)", p0, p1, p2, p3));
	}

	function log(uint p0, uint p1, bool p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,uint,bool,bool)", p0, p1, p2, p3));
	}

	function log(uint p0, uint p1, bool p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,uint,bool,address)", p0, p1, p2, p3));
	}

	function log(uint p0, uint p1, address p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,uint,address,uint)", p0, p1, p2, p3));
	}

	function log(uint p0, uint p1, address p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,uint,address,string)", p0, p1, p2, p3));
	}

	function log(uint p0, uint p1, address p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,uint,address,bool)", p0, p1, p2, p3));
	}

	function log(uint p0, uint p1, address p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,uint,address,address)", p0, p1, p2, p3));
	}

	function log(uint p0, string memory p1, uint p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,string,uint,uint)", p0, p1, p2, p3));
	}

	function log(uint p0, string memory p1, uint p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,string,uint,string)", p0, p1, p2, p3));
	}

	function log(uint p0, string memory p1, uint p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,string,uint,bool)", p0, p1, p2, p3));
	}

	function log(uint p0, string memory p1, uint p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,string,uint,address)", p0, p1, p2, p3));
	}

	function log(uint p0, string memory p1, string memory p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,string,string,uint)", p0, p1, p2, p3));
	}

	function log(uint p0, string memory p1, string memory p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,string,string,string)", p0, p1, p2, p3));
	}

	function log(uint p0, string memory p1, string memory p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,string,string,bool)", p0, p1, p2, p3));
	}

	function log(uint p0, string memory p1, string memory p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,string,string,address)", p0, p1, p2, p3));
	}

	function log(uint p0, string memory p1, bool p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,string,bool,uint)", p0, p1, p2, p3));
	}

	function log(uint p0, string memory p1, bool p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,string,bool,string)", p0, p1, p2, p3));
	}

	function log(uint p0, string memory p1, bool p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,string,bool,bool)", p0, p1, p2, p3));
	}

	function log(uint p0, string memory p1, bool p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,string,bool,address)", p0, p1, p2, p3));
	}

	function log(uint p0, string memory p1, address p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,string,address,uint)", p0, p1, p2, p3));
	}

	function log(uint p0, string memory p1, address p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,string,address,string)", p0, p1, p2, p3));
	}

	function log(uint p0, string memory p1, address p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,string,address,bool)", p0, p1, p2, p3));
	}

	function log(uint p0, string memory p1, address p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,string,address,address)", p0, p1, p2, p3));
	}

	function log(uint p0, bool p1, uint p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,bool,uint,uint)", p0, p1, p2, p3));
	}

	function log(uint p0, bool p1, uint p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,bool,uint,string)", p0, p1, p2, p3));
	}

	function log(uint p0, bool p1, uint p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,bool,uint,bool)", p0, p1, p2, p3));
	}

	function log(uint p0, bool p1, uint p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,bool,uint,address)", p0, p1, p2, p3));
	}

	function log(uint p0, bool p1, string memory p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,bool,string,uint)", p0, p1, p2, p3));
	}

	function log(uint p0, bool p1, string memory p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,bool,string,string)", p0, p1, p2, p3));
	}

	function log(uint p0, bool p1, string memory p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,bool,string,bool)", p0, p1, p2, p3));
	}

	function log(uint p0, bool p1, string memory p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,bool,string,address)", p0, p1, p2, p3));
	}

	function log(uint p0, bool p1, bool p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,bool,bool,uint)", p0, p1, p2, p3));
	}

	function log(uint p0, bool p1, bool p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,bool,bool,string)", p0, p1, p2, p3));
	}

	function log(uint p0, bool p1, bool p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,bool,bool,bool)", p0, p1, p2, p3));
	}

	function log(uint p0, bool p1, bool p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,bool,bool,address)", p0, p1, p2, p3));
	}

	function log(uint p0, bool p1, address p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,bool,address,uint)", p0, p1, p2, p3));
	}

	function log(uint p0, bool p1, address p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,bool,address,string)", p0, p1, p2, p3));
	}

	function log(uint p0, bool p1, address p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,bool,address,bool)", p0, p1, p2, p3));
	}

	function log(uint p0, bool p1, address p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,bool,address,address)", p0, p1, p2, p3));
	}

	function log(uint p0, address p1, uint p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,address,uint,uint)", p0, p1, p2, p3));
	}

	function log(uint p0, address p1, uint p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,address,uint,string)", p0, p1, p2, p3));
	}

	function log(uint p0, address p1, uint p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,address,uint,bool)", p0, p1, p2, p3));
	}

	function log(uint p0, address p1, uint p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,address,uint,address)", p0, p1, p2, p3));
	}

	function log(uint p0, address p1, string memory p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,address,string,uint)", p0, p1, p2, p3));
	}

	function log(uint p0, address p1, string memory p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,address,string,string)", p0, p1, p2, p3));
	}

	function log(uint p0, address p1, string memory p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,address,string,bool)", p0, p1, p2, p3));
	}

	function log(uint p0, address p1, string memory p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,address,string,address)", p0, p1, p2, p3));
	}

	function log(uint p0, address p1, bool p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,address,bool,uint)", p0, p1, p2, p3));
	}

	function log(uint p0, address p1, bool p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,address,bool,string)", p0, p1, p2, p3));
	}

	function log(uint p0, address p1, bool p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,address,bool,bool)", p0, p1, p2, p3));
	}

	function log(uint p0, address p1, bool p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,address,bool,address)", p0, p1, p2, p3));
	}

	function log(uint p0, address p1, address p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,address,address,uint)", p0, p1, p2, p3));
	}

	function log(uint p0, address p1, address p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,address,address,string)", p0, p1, p2, p3));
	}

	function log(uint p0, address p1, address p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,address,address,bool)", p0, p1, p2, p3));
	}

	function log(uint p0, address p1, address p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint,address,address,address)", p0, p1, p2, p3));
	}

	function log(string memory p0, uint p1, uint p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint,uint,uint)", p0, p1, p2, p3));
	}

	function log(string memory p0, uint p1, uint p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint,uint,string)", p0, p1, p2, p3));
	}

	function log(string memory p0, uint p1, uint p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint,uint,bool)", p0, p1, p2, p3));
	}

	function log(string memory p0, uint p1, uint p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint,uint,address)", p0, p1, p2, p3));
	}

	function log(string memory p0, uint p1, string memory p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint,string,uint)", p0, p1, p2, p3));
	}

	function log(string memory p0, uint p1, string memory p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint,string,string)", p0, p1, p2, p3));
	}

	function log(string memory p0, uint p1, string memory p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint,string,bool)", p0, p1, p2, p3));
	}

	function log(string memory p0, uint p1, string memory p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint,string,address)", p0, p1, p2, p3));
	}

	function log(string memory p0, uint p1, bool p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint,bool,uint)", p0, p1, p2, p3));
	}

	function log(string memory p0, uint p1, bool p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint,bool,string)", p0, p1, p2, p3));
	}

	function log(string memory p0, uint p1, bool p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint,bool,bool)", p0, p1, p2, p3));
	}

	function log(string memory p0, uint p1, bool p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint,bool,address)", p0, p1, p2, p3));
	}

	function log(string memory p0, uint p1, address p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint,address,uint)", p0, p1, p2, p3));
	}

	function log(string memory p0, uint p1, address p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint,address,string)", p0, p1, p2, p3));
	}

	function log(string memory p0, uint p1, address p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint,address,bool)", p0, p1, p2, p3));
	}

	function log(string memory p0, uint p1, address p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint,address,address)", p0, p1, p2, p3));
	}

	function log(string memory p0, string memory p1, uint p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string,uint,uint)", p0, p1, p2, p3));
	}

	function log(string memory p0, string memory p1, uint p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string,uint,string)", p0, p1, p2, p3));
	}

	function log(string memory p0, string memory p1, uint p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string,uint,bool)", p0, p1, p2, p3));
	}

	function log(string memory p0, string memory p1, uint p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string,uint,address)", p0, p1, p2, p3));
	}

	function log(string memory p0, string memory p1, string memory p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string,string,uint)", p0, p1, p2, p3));
	}

	function log(string memory p0, string memory p1, string memory p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string,string,string)", p0, p1, p2, p3));
	}

	function log(string memory p0, string memory p1, string memory p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string,string,bool)", p0, p1, p2, p3));
	}

	function log(string memory p0, string memory p1, string memory p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string,string,address)", p0, p1, p2, p3));
	}

	function log(string memory p0, string memory p1, bool p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string,bool,uint)", p0, p1, p2, p3));
	}

	function log(string memory p0, string memory p1, bool p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string,bool,string)", p0, p1, p2, p3));
	}

	function log(string memory p0, string memory p1, bool p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string,bool,bool)", p0, p1, p2, p3));
	}

	function log(string memory p0, string memory p1, bool p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string,bool,address)", p0, p1, p2, p3));
	}

	function log(string memory p0, string memory p1, address p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string,address,uint)", p0, p1, p2, p3));
	}

	function log(string memory p0, string memory p1, address p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string,address,string)", p0, p1, p2, p3));
	}

	function log(string memory p0, string memory p1, address p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string,address,bool)", p0, p1, p2, p3));
	}

	function log(string memory p0, string memory p1, address p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string,address,address)", p0, p1, p2, p3));
	}

	function log(string memory p0, bool p1, uint p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint,uint)", p0, p1, p2, p3));
	}

	function log(string memory p0, bool p1, uint p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint,string)", p0, p1, p2, p3));
	}

	function log(string memory p0, bool p1, uint p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint,bool)", p0, p1, p2, p3));
	}

	function log(string memory p0, bool p1, uint p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint,address)", p0, p1, p2, p3));
	}

	function log(string memory p0, bool p1, string memory p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool,string,uint)", p0, p1, p2, p3));
	}

	function log(string memory p0, bool p1, string memory p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool,string,string)", p0, p1, p2, p3));
	}

	function log(string memory p0, bool p1, string memory p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool,string,bool)", p0, p1, p2, p3));
	}

	function log(string memory p0, bool p1, string memory p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool,string,address)", p0, p1, p2, p3));
	}

	function log(string memory p0, bool p1, bool p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,uint)", p0, p1, p2, p3));
	}

	function log(string memory p0, bool p1, bool p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,string)", p0, p1, p2, p3));
	}

	function log(string memory p0, bool p1, bool p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,bool)", p0, p1, p2, p3));
	}

	function log(string memory p0, bool p1, bool p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,address)", p0, p1, p2, p3));
	}

	function log(string memory p0, bool p1, address p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool,address,uint)", p0, p1, p2, p3));
	}

	function log(string memory p0, bool p1, address p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool,address,string)", p0, p1, p2, p3));
	}

	function log(string memory p0, bool p1, address p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool,address,bool)", p0, p1, p2, p3));
	}

	function log(string memory p0, bool p1, address p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool,address,address)", p0, p1, p2, p3));
	}

	function log(string memory p0, address p1, uint p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address,uint,uint)", p0, p1, p2, p3));
	}

	function log(string memory p0, address p1, uint p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address,uint,string)", p0, p1, p2, p3));
	}

	function log(string memory p0, address p1, uint p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address,uint,bool)", p0, p1, p2, p3));
	}

	function log(string memory p0, address p1, uint p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address,uint,address)", p0, p1, p2, p3));
	}

	function log(string memory p0, address p1, string memory p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address,string,uint)", p0, p1, p2, p3));
	}

	function log(string memory p0, address p1, string memory p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address,string,string)", p0, p1, p2, p3));
	}

	function log(string memory p0, address p1, string memory p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address,string,bool)", p0, p1, p2, p3));
	}

	function log(string memory p0, address p1, string memory p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address,string,address)", p0, p1, p2, p3));
	}

	function log(string memory p0, address p1, bool p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address,bool,uint)", p0, p1, p2, p3));
	}

	function log(string memory p0, address p1, bool p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address,bool,string)", p0, p1, p2, p3));
	}

	function log(string memory p0, address p1, bool p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address,bool,bool)", p0, p1, p2, p3));
	}

	function log(string memory p0, address p1, bool p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address,bool,address)", p0, p1, p2, p3));
	}

	function log(string memory p0, address p1, address p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address,address,uint)", p0, p1, p2, p3));
	}

	function log(string memory p0, address p1, address p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address,address,string)", p0, p1, p2, p3));
	}

	function log(string memory p0, address p1, address p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address,address,bool)", p0, p1, p2, p3));
	}

	function log(string memory p0, address p1, address p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address,address,address)", p0, p1, p2, p3));
	}

	function log(bool p0, uint p1, uint p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint,uint,uint)", p0, p1, p2, p3));
	}

	function log(bool p0, uint p1, uint p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint,uint,string)", p0, p1, p2, p3));
	}

	function log(bool p0, uint p1, uint p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint,uint,bool)", p0, p1, p2, p3));
	}

	function log(bool p0, uint p1, uint p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint,uint,address)", p0, p1, p2, p3));
	}

	function log(bool p0, uint p1, string memory p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint,string,uint)", p0, p1, p2, p3));
	}

	function log(bool p0, uint p1, string memory p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint,string,string)", p0, p1, p2, p3));
	}

	function log(bool p0, uint p1, string memory p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint,string,bool)", p0, p1, p2, p3));
	}

	function log(bool p0, uint p1, string memory p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint,string,address)", p0, p1, p2, p3));
	}

	function log(bool p0, uint p1, bool p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint,bool,uint)", p0, p1, p2, p3));
	}

	function log(bool p0, uint p1, bool p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint,bool,string)", p0, p1, p2, p3));
	}

	function log(bool p0, uint p1, bool p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint,bool,bool)", p0, p1, p2, p3));
	}

	function log(bool p0, uint p1, bool p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint,bool,address)", p0, p1, p2, p3));
	}

	function log(bool p0, uint p1, address p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint,address,uint)", p0, p1, p2, p3));
	}

	function log(bool p0, uint p1, address p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint,address,string)", p0, p1, p2, p3));
	}

	function log(bool p0, uint p1, address p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint,address,bool)", p0, p1, p2, p3));
	}

	function log(bool p0, uint p1, address p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint,address,address)", p0, p1, p2, p3));
	}

	function log(bool p0, string memory p1, uint p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint,uint)", p0, p1, p2, p3));
	}

	function log(bool p0, string memory p1, uint p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint,string)", p0, p1, p2, p3));
	}

	function log(bool p0, string memory p1, uint p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint,bool)", p0, p1, p2, p3));
	}

	function log(bool p0, string memory p1, uint p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint,address)", p0, p1, p2, p3));
	}

	function log(bool p0, string memory p1, string memory p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string,string,uint)", p0, p1, p2, p3));
	}

	function log(bool p0, string memory p1, string memory p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string,string,string)", p0, p1, p2, p3));
	}

	function log(bool p0, string memory p1, string memory p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string,string,bool)", p0, p1, p2, p3));
	}

	function log(bool p0, string memory p1, string memory p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string,string,address)", p0, p1, p2, p3));
	}

	function log(bool p0, string memory p1, bool p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,uint)", p0, p1, p2, p3));
	}

	function log(bool p0, string memory p1, bool p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,string)", p0, p1, p2, p3));
	}

	function log(bool p0, string memory p1, bool p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,bool)", p0, p1, p2, p3));
	}

	function log(bool p0, string memory p1, bool p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,address)", p0, p1, p2, p3));
	}

	function log(bool p0, string memory p1, address p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string,address,uint)", p0, p1, p2, p3));
	}

	function log(bool p0, string memory p1, address p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string,address,string)", p0, p1, p2, p3));
	}

	function log(bool p0, string memory p1, address p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string,address,bool)", p0, p1, p2, p3));
	}

	function log(bool p0, string memory p1, address p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string,address,address)", p0, p1, p2, p3));
	}

	function log(bool p0, bool p1, uint p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint,uint)", p0, p1, p2, p3));
	}

	function log(bool p0, bool p1, uint p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint,string)", p0, p1, p2, p3));
	}

	function log(bool p0, bool p1, uint p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint,bool)", p0, p1, p2, p3));
	}

	function log(bool p0, bool p1, uint p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint,address)", p0, p1, p2, p3));
	}

	function log(bool p0, bool p1, string memory p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,uint)", p0, p1, p2, p3));
	}

	function log(bool p0, bool p1, string memory p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,string)", p0, p1, p2, p3));
	}

	function log(bool p0, bool p1, string memory p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,bool)", p0, p1, p2, p3));
	}

	function log(bool p0, bool p1, string memory p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,address)", p0, p1, p2, p3));
	}

	function log(bool p0, bool p1, bool p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,uint)", p0, p1, p2, p3));
	}

	function log(bool p0, bool p1, bool p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,string)", p0, p1, p2, p3));
	}

	function log(bool p0, bool p1, bool p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,bool)", p0, p1, p2, p3));
	}

	function log(bool p0, bool p1, bool p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,address)", p0, p1, p2, p3));
	}

	function log(bool p0, bool p1, address p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,uint)", p0, p1, p2, p3));
	}

	function log(bool p0, bool p1, address p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,string)", p0, p1, p2, p3));
	}

	function log(bool p0, bool p1, address p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,bool)", p0, p1, p2, p3));
	}

	function log(bool p0, bool p1, address p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,address)", p0, p1, p2, p3));
	}

	function log(bool p0, address p1, uint p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address,uint,uint)", p0, p1, p2, p3));
	}

	function log(bool p0, address p1, uint p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address,uint,string)", p0, p1, p2, p3));
	}

	function log(bool p0, address p1, uint p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address,uint,bool)", p0, p1, p2, p3));
	}

	function log(bool p0, address p1, uint p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address,uint,address)", p0, p1, p2, p3));
	}

	function log(bool p0, address p1, string memory p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address,string,uint)", p0, p1, p2, p3));
	}

	function log(bool p0, address p1, string memory p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address,string,string)", p0, p1, p2, p3));
	}

	function log(bool p0, address p1, string memory p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address,string,bool)", p0, p1, p2, p3));
	}

	function log(bool p0, address p1, string memory p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address,string,address)", p0, p1, p2, p3));
	}

	function log(bool p0, address p1, bool p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,uint)", p0, p1, p2, p3));
	}

	function log(bool p0, address p1, bool p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,string)", p0, p1, p2, p3));
	}

	function log(bool p0, address p1, bool p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,bool)", p0, p1, p2, p3));
	}

	function log(bool p0, address p1, bool p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,address)", p0, p1, p2, p3));
	}

	function log(bool p0, address p1, address p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address,address,uint)", p0, p1, p2, p3));
	}

	function log(bool p0, address p1, address p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address,address,string)", p0, p1, p2, p3));
	}

	function log(bool p0, address p1, address p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address,address,bool)", p0, p1, p2, p3));
	}

	function log(bool p0, address p1, address p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address,address,address)", p0, p1, p2, p3));
	}

	function log(address p0, uint p1, uint p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint,uint,uint)", p0, p1, p2, p3));
	}

	function log(address p0, uint p1, uint p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint,uint,string)", p0, p1, p2, p3));
	}

	function log(address p0, uint p1, uint p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint,uint,bool)", p0, p1, p2, p3));
	}

	function log(address p0, uint p1, uint p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint,uint,address)", p0, p1, p2, p3));
	}

	function log(address p0, uint p1, string memory p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint,string,uint)", p0, p1, p2, p3));
	}

	function log(address p0, uint p1, string memory p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint,string,string)", p0, p1, p2, p3));
	}

	function log(address p0, uint p1, string memory p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint,string,bool)", p0, p1, p2, p3));
	}

	function log(address p0, uint p1, string memory p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint,string,address)", p0, p1, p2, p3));
	}

	function log(address p0, uint p1, bool p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint,bool,uint)", p0, p1, p2, p3));
	}

	function log(address p0, uint p1, bool p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint,bool,string)", p0, p1, p2, p3));
	}

	function log(address p0, uint p1, bool p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint,bool,bool)", p0, p1, p2, p3));
	}

	function log(address p0, uint p1, bool p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint,bool,address)", p0, p1, p2, p3));
	}

	function log(address p0, uint p1, address p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint,address,uint)", p0, p1, p2, p3));
	}

	function log(address p0, uint p1, address p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint,address,string)", p0, p1, p2, p3));
	}

	function log(address p0, uint p1, address p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint,address,bool)", p0, p1, p2, p3));
	}

	function log(address p0, uint p1, address p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint,address,address)", p0, p1, p2, p3));
	}

	function log(address p0, string memory p1, uint p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string,uint,uint)", p0, p1, p2, p3));
	}

	function log(address p0, string memory p1, uint p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string,uint,string)", p0, p1, p2, p3));
	}

	function log(address p0, string memory p1, uint p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string,uint,bool)", p0, p1, p2, p3));
	}

	function log(address p0, string memory p1, uint p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string,uint,address)", p0, p1, p2, p3));
	}

	function log(address p0, string memory p1, string memory p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string,string,uint)", p0, p1, p2, p3));
	}

	function log(address p0, string memory p1, string memory p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string,string,string)", p0, p1, p2, p3));
	}

	function log(address p0, string memory p1, string memory p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string,string,bool)", p0, p1, p2, p3));
	}

	function log(address p0, string memory p1, string memory p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string,string,address)", p0, p1, p2, p3));
	}

	function log(address p0, string memory p1, bool p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string,bool,uint)", p0, p1, p2, p3));
	}

	function log(address p0, string memory p1, bool p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string,bool,string)", p0, p1, p2, p3));
	}

	function log(address p0, string memory p1, bool p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string,bool,bool)", p0, p1, p2, p3));
	}

	function log(address p0, string memory p1, bool p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string,bool,address)", p0, p1, p2, p3));
	}

	function log(address p0, string memory p1, address p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string,address,uint)", p0, p1, p2, p3));
	}

	function log(address p0, string memory p1, address p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string,address,string)", p0, p1, p2, p3));
	}

	function log(address p0, string memory p1, address p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string,address,bool)", p0, p1, p2, p3));
	}

	function log(address p0, string memory p1, address p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string,address,address)", p0, p1, p2, p3));
	}

	function log(address p0, bool p1, uint p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool,uint,uint)", p0, p1, p2, p3));
	}

	function log(address p0, bool p1, uint p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool,uint,string)", p0, p1, p2, p3));
	}

	function log(address p0, bool p1, uint p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool,uint,bool)", p0, p1, p2, p3));
	}

	function log(address p0, bool p1, uint p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool,uint,address)", p0, p1, p2, p3));
	}

	function log(address p0, bool p1, string memory p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool,string,uint)", p0, p1, p2, p3));
	}

	function log(address p0, bool p1, string memory p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool,string,string)", p0, p1, p2, p3));
	}

	function log(address p0, bool p1, string memory p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool,string,bool)", p0, p1, p2, p3));
	}

	function log(address p0, bool p1, string memory p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool,string,address)", p0, p1, p2, p3));
	}

	function log(address p0, bool p1, bool p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,uint)", p0, p1, p2, p3));
	}

	function log(address p0, bool p1, bool p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,string)", p0, p1, p2, p3));
	}

	function log(address p0, bool p1, bool p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,bool)", p0, p1, p2, p3));
	}

	function log(address p0, bool p1, bool p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,address)", p0, p1, p2, p3));
	}

	function log(address p0, bool p1, address p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool,address,uint)", p0, p1, p2, p3));
	}

	function log(address p0, bool p1, address p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool,address,string)", p0, p1, p2, p3));
	}

	function log(address p0, bool p1, address p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool,address,bool)", p0, p1, p2, p3));
	}

	function log(address p0, bool p1, address p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool,address,address)", p0, p1, p2, p3));
	}

	function log(address p0, address p1, uint p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address,uint,uint)", p0, p1, p2, p3));
	}

	function log(address p0, address p1, uint p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address,uint,string)", p0, p1, p2, p3));
	}

	function log(address p0, address p1, uint p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address,uint,bool)", p0, p1, p2, p3));
	}

	function log(address p0, address p1, uint p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address,uint,address)", p0, p1, p2, p3));
	}

	function log(address p0, address p1, string memory p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address,string,uint)", p0, p1, p2, p3));
	}

	function log(address p0, address p1, string memory p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address,string,string)", p0, p1, p2, p3));
	}

	function log(address p0, address p1, string memory p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address,string,bool)", p0, p1, p2, p3));
	}

	function log(address p0, address p1, string memory p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address,string,address)", p0, p1, p2, p3));
	}

	function log(address p0, address p1, bool p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address,bool,uint)", p0, p1, p2, p3));
	}

	function log(address p0, address p1, bool p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address,bool,string)", p0, p1, p2, p3));
	}

	function log(address p0, address p1, bool p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address,bool,bool)", p0, p1, p2, p3));
	}

	function log(address p0, address p1, bool p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address,bool,address)", p0, p1, p2, p3));
	}

	function log(address p0, address p1, address p2, uint p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address,address,uint)", p0, p1, p2, p3));
	}

	function log(address p0, address p1, address p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address,address,string)", p0, p1, p2, p3));
	}

	function log(address p0, address p1, address p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address,address,bool)", p0, p1, p2, p3));
	}

	function log(address p0, address p1, address p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address,address,address)", p0, p1, p2, p3));
	}

}

File 11 of 59 : Context.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/*
 * @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 GSN 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 Context {
    function _msgSender() internal view virtual returns (address payable) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes memory) {
        this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
        return msg.data;
    }
}

File 12 of 59 : IERC1155.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.2 <0.8.0;

import "../../introspection/IERC165.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 IERC1155 is IERC165 {
    /**
     * @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 13 of 59 : IERC1155MetadataURI.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.2 <0.8.0;

import "./IERC1155.sol";

/**
 * @dev Interface of the optional ERC1155MetadataExtension interface, as defined
 * in the https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[EIP].
 *
 * _Available since v3.1._
 */
interface IERC1155MetadataURI is IERC1155 {
    /**
     * @dev Returns the URI for token type `id`.
     *
     * If the `\{id\}` substring is present in the URI, it must be replaced by
     * clients with the actual token type ID.
     */
    function uri(uint256 id) external view returns (string memory);
}

File 14 of 59 : IERC1155Receiver.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "../../introspection/IERC165.sol";

/**
 * _Available since v3.1._
 */
interface IERC1155Receiver is IERC165 {

    /**
        @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 15 of 59 : ERC165.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "./IERC165.sol";

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts may inherit from this and call {_registerInterface} to declare
 * their support of an interface.
 */
abstract contract ERC165 is IERC165 {
    /*
     * bytes4(keccak256('supportsInterface(bytes4)')) == 0x01ffc9a7
     */
    bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7;

    /**
     * @dev Mapping of interface ids to whether or not it's supported.
     */
    mapping(bytes4 => bool) private _supportedInterfaces;

    constructor () internal {
        // Derived contracts need only register support for their own interfaces,
        // we register support for ERC165 itself here
        _registerInterface(_INTERFACE_ID_ERC165);
    }

    /**
     * @dev See {IERC165-supportsInterface}.
     *
     * Time complexity O(1), guaranteed to always use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) public view override returns (bool) {
        return _supportedInterfaces[interfaceId];
    }

    /**
     * @dev Registers the contract as an implementer of the interface defined by
     * `interfaceId`. Support of the actual ERC165 interface is automatic and
     * registering its interface id is not required.
     *
     * See {IERC165-supportsInterface}.
     *
     * Requirements:
     *
     * - `interfaceId` cannot be the ERC165 invalid interface (`0xffffffff`).
     */
    function _registerInterface(bytes4 interfaceId) internal virtual {
        require(interfaceId != 0xffffffff, "ERC165: invalid interface id");
        _supportedInterfaces[interfaceId] = true;
    }
}

File 16 of 59 : Address.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.2 <0.8.0;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @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;
        // solhint-disable-next-line no-inline-assembly
        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");

        // solhint-disable-next-line avoid-low-level-calls, avoid-call-value
        (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");

        // solhint-disable-next-line avoid-low-level-calls
        (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");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.staticcall(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

    function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private 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

                // solhint-disable-next-line no-inline-assembly
                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

File 17 of 59 : IERC165.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <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 IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[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 18 of 59 : EIP712Base.sol
pragma solidity 0.7.4;

contract EIP712Base {

    struct EIP712Domain {
        string name;
        string version;
        uint256 chainId;
        address verifyingContract;
    }

    bytes32 internal constant EIP712_DOMAIN_TYPEHASH = keccak256(bytes("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"));

    bytes32 internal domainSeperator;

    constructor(string memory name, string memory version) public {
        domainSeperator = keccak256(abi.encode(
            EIP712_DOMAIN_TYPEHASH,
            keccak256(bytes(name)),
            keccak256(bytes(version)),
            getChainID(),
            address(this)
        ));
    }

    function getChainID() internal pure returns (uint256 id) {
        return 1;
        // if you want to use the chainId specified by deployment uncomment out below:
        // assembly {
        //     id := chainid()
        // }
    }

    function getDomainSeperator() private view returns(bytes32) {
        return domainSeperator;
    }

    /**
    * Accept message hash and returns hash message in EIP712 compatible form
    * So that it can be used to recover signer from signature signed using EIP712 formatted data
    * https://eips.ethereum.org/EIPS/eip-712
    * "\\x19" makes the encoding deterministic
    * "\\x01" is the version byte to make it compatible to EIP-191
    */
    function toTypedMessageHash(bytes32 messageHash) internal view returns(bytes32) {
        return keccak256(abi.encodePacked("\x19\x01", getDomainSeperator(), messageHash));
    }

}

File 19 of 59 : Equipper.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.4;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/token/ERC1155/ERC1155Receiver.sol";
import "./interfaces/ITournamentV4.sol";
import "./interfaces/IDiceRolls.sol";
import "./Assets.sol";
import "./interfaces/IGameEquipment.sol";

import "hardhat/console.sol";

contract Equipper is ERC1155Receiver {
    using SafeMath for uint256;

    IGameEquipment public immutable equipment;
    ITournamentV4 private immutable _tournament;
    Assets private immutable _assets; // ERC-1155 Assets contract

    constructor(
        address equipmentContract,
        address tournamentContractAddress,
        address assetsContract
    ) {
        equipment = IGameEquipment(equipmentContract);
        _tournament = ITournamentV4(tournamentContractAddress);
        _assets = Assets(assetsContract);
    }

    mapping(uint256 => mapping(uint256 => IGameEquipment.EquipmentMetadata[]))
        public equippings; // tournamentId => gladiatorId => array of equipment

    function gladiatorEquipment(uint256 tournamentId, uint256 gladiatorId)
        public
        view
        returns (IGameEquipment.EquipmentMetadata[] memory)
    {
        return equippings[tournamentId][gladiatorId];
    }

    function handleEquipment(
        address,
        uint256 id,
        uint256 value,
        bytes calldata data // abi encoded uint256,uint256 tournamentId, gladiatorId
    ) internal returns (bool) {
        // TODO: allow fungible equipment
        require(
            value == 1,
            "Equipper#onERC1155BatchReceived: may only add one equipment at a time"
        );

        (uint256 tournamentId, uint256 gladiatorId) =
            abi.decode(data, (uint256, uint256));

        require(
            !_tournament.started(tournamentId),
            "Equipper#No equippings after tournament start"
        );
        require(
            equippings[tournamentId][gladiatorId].length < 3,
            "Equipper#Only 3 Equippings per gladiator per tournament"
        );

        equippings[tournamentId][gladiatorId].push(equipment.getMetadata(id));
        return true;
    }

    function onERC1155Received(
        address operator,
        address from,
        uint256 id,
        uint256 value,
        bytes calldata data
    ) external override returns (bytes4) {
        uint256[] memory ids = new uint256[](1);
        uint256[] memory values = new uint256[](1);
        ids[0] = id;
        values[0] = value;
        onERC1155BatchReceived(operator, from, ids, values, data);
        return IERC1155Receiver.onERC1155Received.selector;
    }

    function onERC1155BatchReceived(
        address, //operator
        address from,
        uint256[] memory ids,
        uint256[] memory values,
        bytes calldata data // abi.encoded (uint256 tournamentId, uint16 faction)
    ) public override returns (bytes4) {
        require(
            msg.sender == address(_assets),
            "Tournament#onERC1155BatchReceived: invalid asset address"
        );

        for (uint256 i = 0; i < ids.length; i++) {
            if (_assets.exists("equipment", ids[i])) {
                require(
                    handleEquipment(from, ids[i], values[i], data),
                    "error handling equipment"
                );
                continue; // stop processing hr
            }
            revert("Unknown token type");
        }

        return IERC1155Receiver.onERC1155BatchReceived.selector;
    }
}

File 20 of 59 : ERC1155Receiver.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "./IERC1155Receiver.sol";
import "../../introspection/ERC165.sol";

/**
 * @dev _Available since v3.1._
 */
abstract contract ERC1155Receiver is ERC165, IERC1155Receiver {
    constructor() internal {
        _registerInterface(
            ERC1155Receiver(0).onERC1155Received.selector ^
            ERC1155Receiver(0).onERC1155BatchReceived.selector
        );
    }
}

File 21 of 59 : ITournamentV4.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.4;
pragma experimental ABIEncoderV2;

import "./IGameLogicV4.sol";
import "./IGameEquipment.sol";
import "./IDiceRolls.sol";

interface ITournamentV4 {
    event RegistrationEvent(
        uint256 indexed tournamentId,
        uint256 indexed gladiatorId,
        uint16 faction,
        uint256 registrationId
    );

    event NewTournament(address indexed creator, uint256 indexed notBefore, uint256 tournamentId);

    event TournamentComplete(uint256 indexed tournamentId, uint256 winner);

    struct Registration {
        uint16 faction;
        uint256 gladiator;
    }

    struct Champion {
        uint16 faction;
        uint256 gladiator;
        uint256 trophy;
    }

    struct TournamentData {
        string name;
        address creator;
        uint256 notBefore;
        uint256 firstRoll;
        uint256 lastRoll;
        IGameLogicV4 gameLogic;
        IDiceRolls roller;
        uint8 totalRounds;
        string[] factions;
        Champion champion;
        Registration[] registrations;
    }

    struct GameGladiator {
        string name;
        uint256 id;
        uint256 registrationId;
        int256 hitPoints;
        uint256 attack;
        uint256 defense;
        uint256 faction;
        IGameEquipment.EquipmentMetadata[] equipment;
        uint256[] equipmentUses;
    }

    struct Round {
        Game[] games;
        uint256 firstRoll;
        uint256 lastRoll;
    }

    struct Game {
        uint256 id;
        uint256 tournamentId;
        bool decided;
        uint8 winner;
        uint256 firstRoll;
        uint256 lastRoll;
        GameGladiator[] players;
    }

    function firstRoll(uint256 tournamentId) external view returns (uint256);

    function notBefore(uint256 tournamentId) external view returns (uint256);

    function started(uint256 tournamentId) external view returns (bool);

    function lastRoll(uint256 tournamentId) external view returns (uint256);

    function roller(uint256 tournamentId) external view returns (IDiceRolls);

    function registrations(uint256 tournamentId) external view returns (Registration[] memory);
}

File 22 of 59 : IDiceRolls.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.4;
pragma experimental ABIEncoderV2;

interface IDiceRolls {
    event DiceRoll(uint256 indexed id, uint256 random);

    struct RollParams {
        uint256 id;
        uint256 random;
        PerformancePair[] performances;
        uint256 blockNumber;
    }

    struct PerformancePair {
        bytes32 name;
        uint256 value;
    }

    function latest() external virtual view returns (uint);

    function roll(uint256 random, PerformancePair[] calldata performance)
        external
        virtual;

    function getLatestRoll() external view virtual returns (RollParams memory);

    function getRoll(uint256 index)
        external
        view
        virtual
        returns (RollParams memory);

    function getRange(uint256 start, uint length)
        external
        view
        virtual
        returns (RollParams[] memory);
}

File 23 of 59 : IGameEquipment.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.4;
pragma experimental ABIEncoderV2;

interface IGameEquipment {
    struct EquipmentMetadata {
        uint256 id;
        string name;
        int256 hitPoints;
        int256 attack;
        int256 defense;
        uint256 percentChanceOfUse;
        uint256 numberOfUsesPerGame;
        bytes32 createdAt;
    }

    function getMetadata(uint id) external virtual returns (EquipmentMetadata memory);

    
}

File 24 of 59 : IGameLogicV4.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.4;
pragma experimental ABIEncoderV2;

import "./ITournamentV4.sol";
import "./IDiceRolls.sol";

interface IGameLogicV4 {

    struct RollReturn {
        uint attacker;
        uint defender;
        int attackRoll;
        int defenseRoll;
        int attackHpAddition;
        int defenseHpAddition;
    }

    function roll(
        ITournamentV4.Game memory game,
        IDiceRolls.RollParams[] memory rolls
    ) external view virtual returns (ITournamentV4.Game memory);

    // This interface allows running a tournament without *creating* a tournament (just seeing results)
    // We *theorize* this is useful as a welcome experience.
    function tournament(
        ITournamentV4.GameGladiator[] memory gladiators,
        IDiceRolls.RollParams[] calldata rolls
    ) external view virtual returns (ITournamentV4.Round[] memory rounds);

    function bracket(
        uint tournamentId,
        int lastRoll
    ) external view virtual returns (ITournamentV4.Round[] memory rounds);

    function tournamentWinner(
        uint tournamentId
    ) external view virtual returns (uint256 registrationId, uint lastRoll);
}

File 25 of 59 : GameLogicV4.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.4;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/math/SafeMath.sol";
import "hardhat/console.sol";
import "./interfaces/IGameLogicV4.sol";
import "./interfaces/IDiceRolls.sol";
import "./interfaces/ITournamentV4.sol";
import "./Gladiator.sol";
import "./Equipper.sol";
import "./interfaces/IGameEquipment.sol";

contract GameLogicV4 is IGameLogicV4 {
    using SafeMath for uint256;

    bytes32 constant HIT_POINTS = "hitpoints";
    bytes32 constant ATTACK = "attack";
    bytes32 constant DEFENSE = "defense";
    bytes32 constant NAME = "name";

    uint256 constant MAX_PERCENTAGE = 10**6;

    Gladiator immutable private _gladiators;
    ITournamentV4 immutable private _tournament;
    Equipper immutable public equipper;

    constructor(
        address gladiatorContract, 
        address tournamentContract, 
        address assetsContract,
        address equipmentContract
    ) {
        _gladiators = Gladiator(gladiatorContract);
        _tournament = ITournamentV4(tournamentContract);
        equipper = new Equipper(equipmentContract, tournamentContract, assetsContract);
    } 

    struct Narrative {
        bool attackerIsWinner;
        uint256 attacker;
        uint256 defender;
        int256 attackRoll;
        int256 defenseRoll;
        int256 attackFactionBonus;
        int256 defenseFactionBonus;
        uint256[] attackEquipment;
        uint256[] defenseEquipment;
        int256 attackerHP;
        int256 defenderHP;
    }

    struct Bonus {
        uint256 id;
        int256 hitPoints;
        int256 attack;
        int256 defense;
    }

    struct OriginalStats {
        uint id;
        int256 hitPoints;
        uint attack;
        uint defense;
    }

    // expected is the uint[] from RollParams#performance
    function getFactionBonuses(
        IDiceRolls.PerformancePair[] memory previous,
        IDiceRolls.PerformancePair[] memory current
    ) internal pure returns (uint256[] memory bonuses) {
        bonuses = new uint256[](current.length);
        for (uint256 i; i < current.length; i++) {
            int256 prev = int256(previous[i].value);
            if (prev == 0) {
                prev = int256(current[i].value);
            }
            // if previous is still 0 then we don't
            // want to divide by zero, so continue
            if (prev == 0) {
                continue;
            }
            int256 bonus = (prev - (int256(current[i].value) * 100)) / prev;
            if (bonus < 0) {
                bonus = 0;
            }
            bonuses[i] = uint256(bonus);
        }
        return bonuses;
    }

    function factionBonus(
        ITournamentV4.Game memory game,
        uint256[] memory bonuses,
        ITournamentV4.GameGladiator memory gladiator
    ) internal view returns (Bonus memory bonus) {
        // console.log("faction: ", gladiator.faction);
        // console.log("bonus length: ", bonuses.length);
        int256 facBonus_ = int256(bonuses[gladiator.faction]);
        bonus.attack = facBonus_;
        bonus.defense = facBonus_;
    }

    function copyUses(uint256[] memory uses)
        internal
        pure
        returns (uint256[] memory newUses)
    {
        newUses = new uint256[](uses.length);
        for (uint256 i; i < uses.length; i++) {
            newUses[i] = uses[i];
        }
        return newUses;
    }

    function equipmentBonuses(
        ITournamentV4.GameGladiator memory gladiator,
        uint256 random,
        bool isAttacker
    ) internal view returns (Bonus memory bonus) {
        // turn to view from pure if turning on console.log
        for (uint256 i; i < gladiator.equipment.length; i++) {
            // console.logBool(isAttacker);
            // console.log('scanning equipment: ', i);
            IGameEquipment.EquipmentMetadata memory equipment =
                gladiator.equipment[i];
            // if it's already been used, then just continue
            if (
                equipment.numberOfUsesPerGame > 0 &&
                gladiator.equipmentUses[i] >= equipment.numberOfUsesPerGame
            ) {
                continue;
            }
            // if this is the attacker, but this equipment does nothing for them
            // then just continue
            if (
                isAttacker && equipment.hitPoints == 0 && equipment.attack == 0
            ) {
                continue;
            }
            // if this is not the attacker, but the equipent only affects attack then
            // don't use it.
            if (
                !isAttacker &&
                equipment.hitPoints == 0 &&
                equipment.defense == 0
            ) {
                continue;
            }
            // otherwise roll the dice to see if it'll be used
            bool useEquipment = true;
            
            // 0 means 100% of the time anything more is a percentage that we roll for;
            if (equipment.percentChanceOfUse > 0) {
                uint256 equipRoll =
                    uint256(keccak256(abi.encodePacked(random, equipment.id)));
                useEquipment = equipRoll.mod(MAX_PERCENTAGE) <=
                    equipment.percentChanceOfUse;
            }

            if (useEquipment) {
                // we'll go ahead and use this one
                // console.log('increasing usage', equipment.name, ' from ', gladiator.equipmentUses[i]);
                gladiator.equipmentUses[i]++;

                bonus.hitPoints += equipment.hitPoints;
                bonus.attack += equipment.attack;
                bonus.defense += equipment.defense;
            }
        }
        return bonus;
    }

    function concatBonuses(Bonus[] memory bonuses)
        internal
        pure
        returns (Bonus memory bonus)
    {
        for (uint256 i; i < bonuses.length; i++) {
            bonus.hitPoints += bonuses[i].hitPoints;
            bonus.attack += bonuses[i].attack;
            bonus.defense += bonuses[i].defense;
        }
        return bonus;
    }

    function getBonuses(
        ITournamentV4.Game memory game,
        uint256 random,
        uint256[] memory factionBonuses,
        ITournamentV4.GameGladiator memory gladiator,
        bool isAttacker
    ) internal view returns (Bonus memory bonus) {
        Bonus[] memory bonuses = new Bonus[](2);
        bonuses[0] = factionBonus(game, factionBonuses, gladiator);
        bonuses[1] = equipmentBonuses(gladiator, random, isAttacker);
        return concatBonuses(bonuses);
    }

    function getRoll(
        ITournamentV4.Game memory game,
        IDiceRolls.RollParams memory roll,
        uint256[] memory factionBonuses,
        uint256 lastWinner
    ) public view returns (RollReturn memory) {
        // console.log('bonus length', bonuses.lenth, 'random: ', roll.random );
        uint256 random = roll.random;
        // console.log("random: (gameid, random) ", game.id, random);

        // first we roll a d3
        // 0 means player 1 is attacker
        // 1 means player 2 is attacker
        // 2 means last player to win is attacker
        uint256 d3 = random.mod(3);
        uint256 attacker = d3;
        if (attacker == 2) {
            attacker = lastWinner;
        }
        // console.log('attacker', attacker);
        uint256 defender = (attacker + 1).mod(game.players.length);

        ITournamentV4.GameGladiator memory attackGladiator =
            game.players[attacker];
        ITournamentV4.GameGladiator memory defendGladiator =
            game.players[defender];

        // console.log("attack/defense gladiator: ", attackGladiator.id, defendGladiator.id);

        uint256 attackRandom =
            uint256(keccak256(abi.encodePacked(attackGladiator.id, random)));
        uint256 defenseRandom =
            uint256(keccak256(abi.encodePacked(defendGladiator.id, random)));

        // console.log('attack/defense random', random, attackRandom, defenseRandom);

        Bonus memory attackBonus =
            getBonuses(
                game,
                attackRandom,
                factionBonuses,
                attackGladiator,
                true
            );
        Bonus memory defenseBonus =
            getBonuses(
                game,
                defenseRandom,
                factionBonuses,
                defendGladiator,
                false
            );

        // console.log('attackGladiator: ', attackGladiator.faction, 'bonus', bonuses[0]);
        // console.log("bonus: (attack,defend): ", bonuses[game.factions[attacker]], bonuses[game.factions[defender]]);
        int256 attackRoll = int256(attackRandom.mod(attackGladiator.attack));
        int256 defenseRoll = int256(defenseRandom.mod(defendGladiator.defense));

        attackRoll += attackBonus.attack;
        defenseRoll += defenseBonus.defense;

        return
            RollReturn({
                attacker: attacker,
                defender: defender,
                attackRoll: attackRoll,
                defenseRoll: defenseRoll,
                attackHpAddition: attackBonus.hitPoints,
                defenseHpAddition: defenseBonus.hitPoints
            });
    }

    // TODO: this is a hacky repeat of roll below, but for now it suffices
    function blowByBlow(
        ITournamentV4.Game memory game,
        IDiceRolls.RollParams[] memory rolls
    ) public view returns (Narrative[] memory narratives) {
        narratives = new Narrative[](rolls.length);
        // console.log("blow by blow: ", game.id, rolls.length);
        uint256 lastWinner = 0;
        IDiceRolls.RollParams memory previousRoll;

        // set it up as 0
        uint256[] memory factionBonuses =
            new uint256[](rolls[0].performances.length);

        for (uint256 i = 0; i < rolls.length; i++) {
            Narrative memory narrative = narratives[i];

            IDiceRolls.RollParams memory roll = rolls[i];
            if (i > 0) {
                factionBonuses = getFactionBonuses(
                    rolls[i - 1].performances,
                    roll.performances
                );
            }

            RollReturn memory rollResult =
                getRoll(game, roll, factionBonuses, lastWinner);

            int256 attackRoll = rollResult.attackRoll;
            int256 defenseRoll = rollResult.defenseRoll;
            uint256 attacker = rollResult.attacker;
            uint256 defender = rollResult.defender;

            narrative.attacker = game.players[attacker].id;
            narrative.defender = game.players[defender].id;
            narrative.attackRoll = attackRoll;
            narrative.defenseRoll = defenseRoll;

            narrative.attackFactionBonus = int256(
                factionBonuses[game.players[attacker].faction]
            );
            narrative.defenseFactionBonus = int256(
                factionBonuses[game.players[defender].faction]
            );

            narrative.attackEquipment = copyUses(
                game.players[attacker].equipmentUses
            );
            narrative.defenseEquipment = copyUses(
                game.players[defender].equipmentUses
            );

            game.players[attacker].hitPoints += rollResult.attackHpAddition;
            game.players[defender].hitPoints += rollResult.defenseHpAddition;

            narrative.attackerHP = game.players[attacker].hitPoints;
            if (attackRoll > defenseRoll) {
                // attack was successful!
                // console.log("successful attack: ");
                // console.logInt(attackRoll - defenseRoll);
                // console.logInt(game.players[defender].hitPoints);
                game.players[defender].hitPoints -= (attackRoll - defenseRoll);
                narrative.defenderHP = game.players[defender].hitPoints;
                // console.log('setting hp to');
                // console.logInt(narrative.defenderHP);
                if (game.players[defender].hitPoints <= 0) {
                    // console.log("death blow after # of rolls: ", i);
                    game.decided = true;
                    game.winner = uint8(attacker);
                    game.lastRoll = roll.id;

                    narrative.attackerIsWinner = true;
                    break;
                }
                lastWinner = attacker;
            } else {
                narrative.defenderHP = game.players[defender].hitPoints;
                lastWinner = defender;
                // console.log("defense win");
            }
        }
        return narratives;
    }

    function roll(
        ITournamentV4.Game memory game,
        IDiceRolls.RollParams[] memory rolls // use view if you enable console.log
    ) public view override returns (ITournamentV4.Game memory) {
        // console.log("roll: ", game.id, rolls.length);
        uint256 lastWinner = 0;
        IDiceRolls.RollParams memory previousRoll;

        // set it up as 0
        uint256[] memory factionBonuses =
            new uint256[](rolls[0].performances.length);

        (uint256 start, bool found) = indexOf(rolls, game.firstRoll);
        // require(found, "no first roll found in rolls");
        if (!found) {
            return game;
        }

        for (uint256 i = start; i < rolls.length; i++) {
            IDiceRolls.RollParams memory roll = rolls[i];
            if (i > 0) {
                factionBonuses = getFactionBonuses(
                    rolls[i - 1].performances,
                    roll.performances
                );
            }

            RollReturn memory rollResult =
                getRoll(game, roll, factionBonuses, lastWinner);

            int256 attackRoll = rollResult.attackRoll;
            int256 defenseRoll = rollResult.defenseRoll;

            game.players[rollResult.attacker].hitPoints += rollResult
                .attackHpAddition;
            game.players[rollResult.defender].hitPoints += rollResult
                .defenseHpAddition;

            if (attackRoll > defenseRoll) {
                // attack was successful!
                // console.log("successful attack: ", attackRoll.sub(defenseRoll));
                game.players[rollResult.defender].hitPoints -= (attackRoll -
                    defenseRoll);
                if (game.players[rollResult.defender].hitPoints <= 0) {
                    // console.log("death blow after # of rolls: ", i);
                    game.decided = true;
                    game.winner = uint8(rollResult.attacker);
                    game.lastRoll = roll.id;
                    break;
                }
                lastWinner = rollResult.attacker;
            } else {
                lastWinner = rollResult.defender;
                // console.log("defense win");
            }
        }
        return game;
    }

    // TODO: binary search
    function indexOf(IDiceRolls.RollParams[] memory rolls, uint256 id)
        internal
        view
        returns (uint256 idx, bool found)
    {
        for (idx = 0; idx < rolls.length; idx++) {
            if (rolls[idx].id == id) {
                return (idx, true);
            }
        }
        return (0, false);
    }

    function _getRound(
        ITournamentV4.GameGladiator[] memory roundPlayers,
        IDiceRolls.RollParams[] memory rolls,
        uint256 firstRollIndex
    ) internal view returns (ITournamentV4.Round memory round) {
        round.games = new ITournamentV4.Game[](roundPlayers.length.div(2));
        // console.log("fetching: ", firstRollIndex);
        if (firstRollIndex >= rolls.length) {
            uint256 gameId = 0;
            for (uint256 i; i < roundPlayers.length; i += 2) {
                ITournamentV4.Game memory game;

                ITournamentV4.GameGladiator[] memory players =
                    new ITournamentV4.GameGladiator[](2);
                players[0] = roundPlayers[i];
                players[1] = roundPlayers[i + 1];

                game.players = players;
                game.id = gameId;
                round.games[gameId] = game;
                gameId++;
            }
            return round;
        }
        uint256 firstRoll = rolls[firstRollIndex].id;
        round.firstRoll = firstRoll;

        bool lastGameIsFinished = true;

        uint256 gameId = 0;
        for (uint256 i; i < roundPlayers.length; i += 2) {
            ITournamentV4.Game memory game;

            ITournamentV4.GameGladiator[] memory players =
                new ITournamentV4.GameGladiator[](2);
            players[0] = roundPlayers[i];
            players[1] = roundPlayers[i + 1];
            // console.log("player 0: ", players[0].id);
            // console.log("player 1: ", players[1].id);

            game.players = players;
            game.id = gameId;
            if (lastGameIsFinished) {
                game.firstRoll = firstRoll;
                // console.log("calculatin game", i, game.id, firstRoll);
                // console.log(game.players.length);
                // only calculate if the last game was finished
                game = roll(game, rolls);
            }
            if (game.decided) {
                // console.log("setting firstRoll: ", game.lastRoll);
                firstRoll = game.lastRoll + 1;
                lastGameIsFinished = true;
            } else {
                lastGameIsFinished = false;
            }
            round.games[gameId] = game;
            gameId++;
        }
        if (lastGameIsFinished) {
            round.lastRoll = firstRoll - 1; // firstRoll has been updating
        }
        return round;
    }

     // TODO: binary search
    function indexOfGladiator(OriginalStats[] memory originalStats, uint256 id)
        internal
        pure
        returns (uint256 idx)
    {
        for (idx = 0; idx < originalStats.length; idx++) {
            if (originalStats[idx].id == id) {
                return idx;
            }
        }
        require(false, "should not get here");
        return 0;
    }

    function restoreGladiator(
        ITournamentV4.GameGladiator memory gladiator,
        OriginalStats[] memory originalStats
    ) internal pure returns (ITournamentV4.GameGladiator memory) {
        uint idx = indexOfGladiator(originalStats, gladiator.id);
        OriginalStats memory stats = originalStats[idx];
        gladiator.hitPoints = stats.hitPoints;
        gladiator.attack = stats.attack;
        gladiator.defense = stats.defense;
        gladiator.equipmentUses = new uint[](gladiator.equipmentUses.length);
        return gladiator;
    }

    function getWinners(
        ITournamentV4.Round memory round,
        OriginalStats[] memory originalStats
    )
        internal
        pure
        returns (ITournamentV4.GameGladiator[] memory players)
    {
        players = new ITournamentV4.GameGladiator[](round.games.length);
        for (uint256 i; i < round.games.length; i++) {
            ITournamentV4.Game memory game = round.games[i];
            require(game.decided, "Winners not decided");
            players[i] = restoreGladiator(game.players[game.winner], originalStats);
        }
        return players;
    }

    function tournamentWinner(
        uint tournamentId
    ) public view override returns (uint256 registrationId, uint256 lastRoll) {
        ITournamentV4.Round[] memory rounds = bracket(tournamentId, -1);
        ITournamentV4.Round memory round = rounds[rounds.length - 1];
        ITournamentV4.Game memory game = round.games[0];
        require(game.decided, "Tournament Not Decided");
        return (game.players[game.winner].registrationId, game.lastRoll);
    }

    function tournament(
        ITournamentV4.GameGladiator[] memory gladiators,
        IDiceRolls.RollParams[] memory rolls
    ) public view override returns (ITournamentV4.Round[] memory rounds) {
        ITournamentV4.Round memory currentRound;
        rounds = new ITournamentV4.Round[](log2(gladiators.length)); // TODO: check this math
        
        OriginalStats[] memory originalStats = new OriginalStats[](gladiators.length);
        for (uint i = 0; i < gladiators.length; i++) {
            originalStats[i] = OriginalStats({
                id: gladiators[i].id,
                hitPoints: gladiators[i].hitPoints,
                attack: gladiators[i].attack,
                defense: gladiators[i].defense
            });
        }

        for (uint256 i = 0; i < rounds.length; i++) {
            if (i == 0) {
                // console.log("round 0");
                currentRound = _getRound(gladiators, rolls, 0);
            } else {
                // console.log("round ", i);
                (uint256 start, bool found) =
                    indexOf(rolls, currentRound.lastRoll);
                require(found, "no roll found");
                currentRound = _getRound(
                    getWinners(currentRound, originalStats),
                    rolls,
                    start + 1
                );
            }
            rounds[i] = currentRound;
            if (!currentRound.games[currentRound.games.length - 1].decided) {
                break;
            }
        }

        return rounds;
    }

    function bracket(uint tournamentId, int specifiedLastRoll) public view override returns (ITournamentV4.Round[] memory rounds) {
        ITournamentV4.GameGladiator[] memory gladiators = gameGladiators(tournamentId);
        // if tournament hasn't started yet
        if (!_tournament.started(tournamentId)) {
            IDiceRolls.RollParams[] memory rolls;
            return tournament(gladiators, rolls);
        }

        IDiceRolls roller = _tournament.roller(tournamentId);
        uint firstRoll = _tournament.firstRoll(tournamentId);
        
        uint lastRoll;

        // user sends in -1 to mean "the whole tournament
        if (specifiedLastRoll < 0) {
            lastRoll = _tournament.lastRoll(tournamentId);
            if (lastRoll == 0) {
                lastRoll = roller.latest();
            }
        } else {
            lastRoll = uint(specifiedLastRoll);
        }
        
        return tournament(gladiators, roller.getRange(firstRoll, lastRoll));
    }


    // Gladiator stuff

    function getGladiator(
        uint256 registrationId,
        uint256 tournamentId,
        ITournamentV4.Registration memory reg
    ) internal view returns (ITournamentV4.GameGladiator memory gladiator) {
        uint256 id = reg.gladiator;
        gladiator.id = id;
        gladiator.faction = reg.faction;
        gladiator.registrationId = registrationId;
        gladiator.name = _gladiators.name(id);
        gladiator.hitPoints = int256(_gladiators.getProperty(id, HIT_POINTS));
        gladiator.attack = uint256(_gladiators.getProperty(id, ATTACK));
        gladiator.defense = uint256(_gladiators.getProperty(id, DEFENSE));
        gladiator.equipment = equipper.gladiatorEquipment(tournamentId, id);
        gladiator.equipmentUses = new uint256[](gladiator.equipment.length);
        return gladiator;
    }

    function gameGladiators(uint256 tournamentId)
        public
        view
        returns (ITournamentV4.GameGladiator[] memory gladiators)
    {
        ITournamentV4.Registration[] memory registrations = _tournament.registrations(tournamentId);
        return _gameGladiators(tournamentId, registrations);
    }

    function _gameGladiators(
        uint256 tournamentId,
        ITournamentV4.Registration[] memory registrations
    ) internal view returns (ITournamentV4.GameGladiator[] memory gladiators) {
        gladiators = new ITournamentV4.GameGladiator[](registrations.length);
        for (uint256 i; i < registrations.length; i++) {
            gladiators[i] = getGladiator(i, tournamentId, registrations[i]);
        }
        return gladiators;
    }
    
 // see: https://ethereum.stackexchange.com/questions/8086/logarithm-math-operation-in-solidity
    function log2(uint256 x) internal pure returns (uint256 y) {
        assembly {
            let arg := x
            x := sub(x, 1)
            x := or(x, div(x, 0x02))
            x := or(x, div(x, 0x04))
            x := or(x, div(x, 0x10))
            x := or(x, div(x, 0x100))
            x := or(x, div(x, 0x10000))
            x := or(x, div(x, 0x100000000))
            x := or(x, div(x, 0x10000000000000000))
            x := or(x, div(x, 0x100000000000000000000000000000000))
            x := add(x, 1)
            let m := mload(0x40)
            mstore(
                m,
                0xf8f9cbfae6cc78fbefe7cdc3a1793dfcf4f0e8bbd8cec470b6a28a7a5a3e1efd
            )
            mstore(
                add(m, 0x20),
                0xf5ecf1b3e9debc68e1d9cfabc5997135bfb7a7a3938b7b606b5b4b3f2f1f0ffe
            )
            mstore(
                add(m, 0x40),
                0xf6e4ed9ff2d6b458eadcdf97bd91692de2d4da8fd2d0ac50c6ae9a8272523616
            )
            mstore(
                add(m, 0x60),
                0xc8c0b887b0a8a4489c948c7f847c6125746c645c544c444038302820181008ff
            )
            mstore(
                add(m, 0x80),
                0xf7cae577eec2a03cf3bad76fb589591debb2dd67e0aa9834bea6925f6a4a2e0e
            )
            mstore(
                add(m, 0xa0),
                0xe39ed557db96902cd38ed14fad815115c786af479b7e83247363534337271707
            )
            mstore(
                add(m, 0xc0),
                0xc976c13bb96e881cb166a933a55e490d9d56952b8d4e801485467d2362422606
            )
            mstore(
                add(m, 0xe0),
                0x753a6d1b65325d0c552a4d1345224105391a310b29122104190a110309020100
            )
            mstore(0x40, add(m, 0x100))
            let
                magic
            := 0x818283848586878898a8b8c8d8e8f929395969799a9b9d9e9faaeb6bedeeff
            let
                shift
            := 0x100000000000000000000000000000000000000000000000000000000000000
            let a := div(mul(x, magic), shift)
            y := div(mload(add(m, sub(255, a))), shift)
            y := add(
                y,
                mul(
                    256,
                    gt(
                        arg,
                        0x8000000000000000000000000000000000000000000000000000000000000000
                    )
                )
            )
        }
    }
}

File 26 of 59 : Gladiator.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.4;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/math/Math.sol";
import "@openzeppelin/contracts/token/ERC1155/ERC1155Receiver.sol";
import "@openzeppelin/contracts/utils/EnumerableSet.sol";
import "./meta/EIP712MetaTransaction.sol";
import "./interfaces/IAssets.sol";
import "./interfaces/IRegisterableAsset.sol";
import "./EnumerableMap.sol";
import "./EnumerableStringMap.sol";
import "./Constants.sol";

import "hardhat/console.sol";

contract Gladiator is IRegisterableAsset, ERC1155Receiver, EIP712MetaTransaction {
  using SafeMath for uint256;
  using EnumerableMap for EnumerableMap.Map;
  using EnumerableStringMap for EnumerableStringMap.Map;
  using EnumerableSet for EnumerableSet.UintSet;

  bytes32 constant ASSET_NAME = "gladiator";
  uint256 constant TOTAL_SUPPLY = 2**24;

  uint256 constant ASSET_DECIMALS = 10**18;

  IAssets immutable public assets;

  struct Metadata {
    string name;
    string image;
    EnumerableMap.Map properties;
    EnumerableStringMap.Map extendedProperties;
  }

  mapping(uint256 => Metadata) private _metadata;

  mapping(uint256 => EnumerableSet.UintSet) private _inventory;

  mapping(uint256 => mapping(uint256 => uint256)) private _balances;

  constructor(address assetsAddress) public EIP712MetaTransaction("Gladiator", "1") {
    assets = IAssets(assetsAddress);
  }

  function assetName() override public pure returns (bytes32) {
    return ASSET_NAME;
  }

  function assetTotalSupply() override public pure returns (uint256) {
    return TOTAL_SUPPLY;
  }

  function assetIsNFT() override public pure returns (bool) {
    return true;
  }

  function assetOperators() override public view returns (address[] memory) {
    address[] memory operators = new address[](1);
    operators[0] = address(this);
    return operators;
  }

  function idRange() public view returns (uint256, uint256) {
    return assets.idRange(ASSET_NAME);
  }

  function mint(
    address account,
    string calldata name,
    string calldata image,
    EnumerableMap.MapEntry[] calldata properties,
    EnumerableStringMap.MapEntry[] calldata extendedProperties
  ) external returns (uint256) {
    // uint256 propsLength = propertyPairs.length;
    // require((propsLength % 2) == 0, "propertyPairs must have even number of members (k/v)");

    uint256[] memory ids = assets.mint(account, ASSET_NAME, 1, "");
    uint256 id = ids[0];

    Metadata storage metadata = _metadata[id];
    metadata.name = name;
    metadata.image = image;

    EnumerableMap.Map storage _properties = metadata.properties;
    EnumerableStringMap.Map storage _extendedProperties = metadata.extendedProperties;

    for (uint i; i < properties.length; i++) {
      _properties.set(properties[i].key, properties[i].value);
    }

    for (uint i; i < extendedProperties.length; i++) {
      _extendedProperties.set(extendedProperties[i].key, extendedProperties[i].value);
    }

    _properties.set("generation", bytes32(_generationOfID(id)));
    _properties.set("createdAt", bytes32(block.timestamp));

    return id;
  }

  // Returns integer representing generation of id
  // generation correlates to number of digits, floored at 2
  // 0-99 gen 0
  // 100-999 gen 1
  // 1000-9999 gen 2
  // etc
  function _generationOfID(uint256 id) internal view returns (uint256) {
    (uint256 gladiatorMinID, uint256 _) = assets.idRange(ASSET_NAME);
    uint256 mintNumber = id - gladiatorMinID;

    uint8 digits = 0;
    while (mintNumber != 0) {
      mintNumber /= 10;
      digits++;
    }

    return Math.max(digits, 2) - 2;
  }

  function exists(
    uint256 id
  ) public view returns (bool) {
    return assets.exists(ASSET_NAME, id);
  }

  function name(
    uint256 id
  ) external view returns (string memory) {
    return _metadata[id].name;
  }

  function image(
    uint256 id
  ) external view returns (string memory) {
    return _metadata[id].image;
  }

  function prestige(
    uint256 id
  ) external view returns (uint256) {
    (uint256 prestigeTokenID, uint256 _) = assets.idRange(Constants.prestigeAssetName());
    return _balances[id][prestigeTokenID];
  }

  function properties(
    uint256 id
  ) external view returns (EnumerableMap.MapEntry[] memory) {
    EnumerableMap.Map storage _properties = _metadata[id].properties;
    uint256 propsLength = _properties.length(); 
    EnumerableMap.MapEntry[] memory propertyPairs = new EnumerableMap.MapEntry[](propsLength);
    for (uint256 i = 0; i < propsLength; i++) {
      (bytes32 k, bytes32 v) = _properties.at(i);
      propertyPairs[i] = EnumerableMap.MapEntry({
        key: k,
        value: v
      });
    }
    return propertyPairs;
  }

  function getProperty(
    uint256 id,
    bytes32 key
  ) external view returns (bytes32) {
    return _metadata[id].properties.get(key);
  }
  
  function extendedProperties(
    uint256 id
  ) external view returns (EnumerableStringMap.MapEntry[] memory) {
    EnumerableStringMap.Map storage _extendedProperties = _metadata[id].extendedProperties;
    uint256 propsLength = _extendedProperties.length(); 
    EnumerableStringMap.MapEntry[] memory propertyPairs = new EnumerableStringMap.MapEntry[](propsLength);
    for (uint256 i = 0; i < propsLength; i++) {
      (bytes32 k, string memory v) = _extendedProperties.at(i);
      propertyPairs[i] = EnumerableStringMap.MapEntry({
        key: k,
        value: v
      });
    }
    return propertyPairs;
  }

  function getExtendedProperty(
    uint256 id,
    bytes32 key
  ) external view returns (string memory) {
    return _metadata[id].extendedProperties.get(key);
  }

  function inventory(
    uint256 id
  ) external view returns (uint256[] memory) {
    EnumerableSet.UintSet storage set = _inventory[id];
    uint256[] memory ids = new uint256[](set.length());
    for (uint256 i = 0; i < ids.length; i++) {
      ids[i] = set.at(i);
    }
    return ids;
  }

  function balances(
    uint256 id
  ) external view returns (uint256[] memory) {
    EnumerableSet.UintSet storage set = _inventory[id];
    uint256[] memory ret = new uint256[](set.length());
    for (uint256 i = 0; i < ret.length; i++) {
      ret[i] = _balances[id][set.at(i)];
    }
    return ret;
  }

  function balanceOf(
    uint256 id,
    uint256 tokenID
  ) external view returns (uint256) {
    return _balances[id][tokenID];
  }

  function safeTransferFrom(
        uint gladiator,
        address to,
        uint256 id,
        uint256 amount,
        bytes memory data
  ) public {
    address sender = msgSender();
    require(assets.isApprovedOrOwner(sender, sender, gladiator), "You must own the the gladiator to transfer balances");
    uint bal = _balances[gladiator][id];
    _balances[gladiator][id] = bal.sub(amount); // this will error if the sub doesn't go through.
    assets.safeTransferFrom(address(this), to, id, amount, data);
  }

  function onERC1155Received(
    address operator,
    address from,
    uint256 id,
    uint256 value,
    bytes calldata data
  ) external override returns(bytes4) {
    uint256[] memory ids = new uint256[](1);
    uint256[] memory values = new uint256[](1);
    ids[0] = id;
    values[0] = value;
    onERC1155BatchReceived(operator, from, ids, values, data);
    return IERC1155Receiver.onERC1155Received.selector;
  }

  function onERC1155BatchReceived(
    address operator,
    address from,
    uint256[] memory ids,
    uint256[] memory values,
    bytes calldata data // abi.encoded (uint256 gladiatorID)
  ) public override returns(bytes4) {
    require(msgSender() == address(assets), "Gladiator can only receive items from Assets contract");

    (uint256 gladiatorID) = abi.decode(data, (uint256));
    require(exists(gladiatorID), "gladiator does not exist");

    EnumerableSet.UintSet storage gladiatorInventory = _inventory[gladiatorID];
    for (uint i = 0; i < ids.length; i++) {
      gladiatorInventory.add(ids[i]);
      _balances[gladiatorID][ids[i]] += values[i];
    }

    return IERC1155Receiver.onERC1155BatchReceived.selector;
  }
}

File 27 of 59 : Math.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    /**
     * @dev Returns the largest of two numbers.
     */
    function max(uint256 a, uint256 b) internal pure returns (uint256) {
        return a >= b ? a : b;
    }

    /**
     * @dev Returns the smallest of two numbers.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two numbers. The result is rounded towards
     * zero.
     */
    function average(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b) / 2 can overflow, so we distribute
        return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2);
    }
}

File 28 of 59 : EnumerableMap.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

// Copied from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v3.3/contracts/utils/EnumerableMap.sol
// exposes all private methods, resulting in pure byte32 => byte32 functions

/**
 * @dev Library for managing an enumerable variant of Solidity's
 * https://solidity.readthedocs.io/en/latest/types.html#mapping-types[`mapping`]
 * type.
 *
 * Maps have the following properties:
 *
 * - Entries are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Entries are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```
 * contract Example {
 *     // Add the library methods
 *     using EnumerableMap for EnumerableMap.UintToAddressMap;
 *
 *     // Declare a set state variable
 *     EnumerableMap.UintToAddressMap internal myMap;
 * }
 * ```
 *
 * As of v3.0.0, only maps of type `uint256 -> address` (`UintToAddressMap`) are
 * supported.
 */
library EnumerableMap {
    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Map type with
    // bytes32 keys and values.
    // The Map implementation uses internal functions, and user-facing
    // implementations (such as Uint256ToAddressMap) are just wrappers around
    // the underlying Map.
    // This means that we can only create new EnumerableMaps for types that fit
    // in bytes32.

    struct MapEntry {
        bytes32 key;
        bytes32 value;
    }

    struct Map {
        // Storage of map keys and values
        MapEntry[] _entries;

        // Position of the entry defined by a key in the `entries` array, plus 1
        // because index 0 means a key is not in the map.
        mapping (bytes32 => uint256) _indexes;
    }

    /**
     * @dev Adds a key-value pair to a map, or updates the value for an existing
     * key. O(1).
     *
     * Returns true if the key was added to the map, that is if it was not
     * already present.
     */
    function set(Map storage map, bytes32 key, bytes32 value) internal returns (bool) {
        // We read and store the key's index to prevent multiple reads from the same storage slot
        uint256 keyIndex = map._indexes[key];

        if (keyIndex == 0) { // Equivalent to !contains(map, key)
            map._entries.push(MapEntry({ key: key, value: value }));
            // The entry is stored at length-1, but we add 1 to all indexes
            // and use 0 as a sentinel value
            map._indexes[key] = map._entries.length;
            return true;
        } else {
            map._entries[keyIndex - 1].value = value;
            return false;
        }
    }

    /**
     * @dev Removes a key-value pair from a map. O(1).
     *
     * Returns true if the key was removed from the map, that is if it was present.
     */
    function remove(Map storage map, bytes32 key) internal returns (bool) {
        // We read and store the key's index to prevent multiple reads from the same storage slot
        uint256 keyIndex = map._indexes[key];

        if (keyIndex != 0) { // Equivalent to contains(map, key)
            // To delete a key-value pair from the _entries array in O(1), we swap the entry to delete with the last one
            // in the array, and then remove the last entry (sometimes called as 'swap and pop').
            // This modifies the order of the array, as noted in {at}.

            uint256 toDeleteIndex = keyIndex - 1;
            uint256 lastIndex = map._entries.length - 1;

            // When the entry to delete is the last one, the swap operation is unnecessary. However, since this occurs
            // so rarely, we still do the swap anyway to avoid the gas cost of adding an 'if' statement.

            MapEntry storage lastEntry = map._entries[lastIndex];

            // Move the last entry to the index where the entry to delete is
            map._entries[toDeleteIndex] = lastEntry;
            // Update the index for the moved entry
            map._indexes[lastEntry.key] = toDeleteIndex + 1; // All indexes are 1-based

            // Delete the slot where the moved entry was stored
            map._entries.pop();

            // Delete the index for the deleted slot
            delete map._indexes[key];

            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Returns true if the key is in the map. O(1).
     */
    function contains(Map storage map, bytes32 key) internal view returns (bool) {
        return map._indexes[key] != 0;
    }

    /**
     * @dev Returns the number of key-value pairs in the map. O(1).
     */
    function length(Map storage map) internal view returns (uint256) {
        return map._entries.length;
    }

   /**
    * @dev Returns the key-value pair stored at position `index` in the map. O(1).
    *
    * Note that there are no guarantees on the ordering of entries inside the
    * array, and it may change when more entries are added or removed.
    *
    * Requirements:
    *
    * - `index` must be strictly less than {length}.
    */
    function at(Map storage map, uint256 index) internal view returns (bytes32, bytes32) {
        require(map._entries.length > index, "EnumerableMap: index out of bounds");

        MapEntry storage entry = map._entries[index];
        return (entry.key, entry.value);
    }

    /**
     * @dev Returns the value associated with `key`.  O(1).
     *
     * Requirements:
     *
     * - `key` must be in the map.
     */
    function get(Map storage map, bytes32 key) internal view returns (bytes32) {
        return get(map, key, "EnumerableMap: nonexistent key");
    }

    /**
     * @dev Same as {get}, with a custom error message when `key` is not in the map.
     */
    function get(Map storage map, bytes32 key, string memory errorMessage) internal view returns (bytes32) {
        uint256 keyIndex = map._indexes[key];
        require(keyIndex != 0, errorMessage); // Equivalent to contains(map, key)
        return map._entries[keyIndex - 1].value; // All indexes are 1-based
    }
}

File 29 of 59 : EnumerableStringMap.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

// this is similar to ./EnumberableMap but uses *strings* for values

/**
 * @dev Library for managing an enumerable variant of Solidity's
 * https://solidity.readthedocs.io/en/latest/types.html#mapping-types[`mapping`]
 * type.
 *
 * Maps have the following properties:
 *
 * - Entries are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Entries are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```
 * contract Example {
 *     // Add the library methods
 *     using EnumerableMap for EnumerableMap.UintToAddressMap;
 *
 *     // Declare a set state variable
 *     EnumerableMap.UintToAddressMap internal myMap;
 * }
 * ```
 *
 * As of v3.0.0, only maps of type `uint256 -> address` (`UintToAddressMap`) are
 * supported.
 */
library EnumerableStringMap {
    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Map type with
    // bytes32 keys and values.
    // The Map implementation uses internal functions, and user-facing
    // implementations (such as Uint256ToAddressMap) are just wrappers around
    // the underlying Map.
    // This means that we can only create new EnumerableMaps for types that fit
    // in bytes32.

    struct MapEntry {
        bytes32 key;
        string value;
    }

    struct Map {
        // Storage of map keys and values
        MapEntry[] _entries;

        // Position of the entry defined by a key in the `entries` array, plus 1
        // because index 0 means a key is not in the map.
        mapping (bytes32 => uint256) _indexes;
    }

    /**
     * @dev Adds a key-value pair to a map, or updates the value for an existing
     * key. O(1).
     *
     * Returns true if the key was added to the map, that is if it was not
     * already present.
     */
    function set(Map storage map, bytes32 key, string memory value) internal returns (bool) {
        // We read and store the key's index to prevent multiple reads from the same storage slot
        uint256 keyIndex = map._indexes[key];

        if (keyIndex == 0) { // Equivalent to !contains(map, key)
            map._entries.push(MapEntry({ key: key, value: value }));
            // The entry is stored at length-1, but we add 1 to all indexes
            // and use 0 as a sentinel value
            map._indexes[key] = map._entries.length;
            return true;
        } else {
            map._entries[keyIndex - 1].value = value;
            return false;
        }
    }

    /**
     * @dev Removes a key-value pair from a map. O(1).
     *
     * Returns true if the key was removed from the map, that is if it was present.
     */
    function remove(Map storage map, bytes32 key) internal returns (bool) {
        // We read and store the key's index to prevent multiple reads from the same storage slot
        uint256 keyIndex = map._indexes[key];

        if (keyIndex != 0) { // Equivalent to contains(map, key)
            // To delete a key-value pair from the _entries array in O(1), we swap the entry to delete with the last one
            // in the array, and then remove the last entry (sometimes called as 'swap and pop').
            // This modifies the order of the array, as noted in {at}.

            uint256 toDeleteIndex = keyIndex - 1;
            uint256 lastIndex = map._entries.length - 1;

            // When the entry to delete is the last one, the swap operation is unnecessary. However, since this occurs
            // so rarely, we still do the swap anyway to avoid the gas cost of adding an 'if' statement.

            MapEntry storage lastEntry = map._entries[lastIndex];

            // Move the last entry to the index where the entry to delete is
            map._entries[toDeleteIndex] = lastEntry;
            // Update the index for the moved entry
            map._indexes[lastEntry.key] = toDeleteIndex + 1; // All indexes are 1-based

            // Delete the slot where the moved entry was stored
            map._entries.pop();

            // Delete the index for the deleted slot
            delete map._indexes[key];

            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Returns true if the key is in the map. O(1).
     */
    function contains(Map storage map, bytes32 key) internal view returns (bool) {
        return map._indexes[key] != 0;
    }

    /**
     * @dev Returns the number of key-value pairs in the map. O(1).
     */
    function length(Map storage map) internal view returns (uint256) {
        return map._entries.length;
    }

   /**
    * @dev Returns the key-value pair stored at position `index` in the map. O(1).
    *
    * Note that there are no guarantees on the ordering of entries inside the
    * array, and it may change when more entries are added or removed.
    *
    * Requirements:
    *
    * - `index` must be strictly less than {length}.
    */
    function at(Map storage map, uint256 index) internal view returns (bytes32, string memory) {
        require(map._entries.length > index, "EnumerableMap: index out of bounds");

        MapEntry storage entry = map._entries[index];
        return (entry.key, entry.value);
    }

    /**
     * @dev Returns the value associated with `key`.  O(1).
     *
     * Requirements:
     *
     * - `key` must be in the map.
     */
    function get(Map storage map, bytes32 key) internal view returns (string memory) {
        return get(map, key, "EnumerableMap: nonexistent key");
    }

    /**
     * @dev Same as {get}, with a custom error message when `key` is not in the map.
     */
    function get(Map storage map, bytes32 key, string memory errorMessage) internal view returns (string memory) {
        uint256 keyIndex = map._indexes[key];
        require(keyIndex != 0, errorMessage); // Equivalent to contains(map, key)
        return map._entries[keyIndex - 1].value; // All indexes are 1-based
    }
}

File 30 of 59 : Marketplace.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.4;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC1155/ERC1155Receiver.sol";

import "@uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol";
import "@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol";
import "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol";
import "./libraries/UniswapV2Library.sol";

import "./interfaces/IAssets.sol";
import "./interfaces/IAssetsERC20Wrapper.sol";
import "./interfaces/IGameEquipment.sol";
import "hardhat/console.sol";

interface IWrapperFactory {
    function getWrapper(uint256 tokenID) external view returns (address); // mapping of tokenID to address

    function createWrapper(
        uint256 tokenID,
        string calldata name,
        string calldata symbol
    ) external returns (address);
}

contract Marketplace is Ownable, ERC1155Receiver {
    using SafeMath for uint256;

    event Bootstrap(uint256 indexed itemID, uint256 prestigeAmount, uint256 tokenAmount);
    event Mint(uint256 indexed itemID, uint256 quantity);
    event Buy(address indexed from, uint256 indexed itemID, uint256 prestigeAmount, uint256 tokenAmount);
    event Sell(address indexed from, uint256 indexed itemID, uint256 prestigeAmount, uint256 tokenAmount);

    uint256 constant maxUint = 2**254;
    bytes4 constant bootstrapSelector = bytes4(keccak256("boot"));

    uint256 private immutable _ptgID;
    IAssets private immutable _assets;
    IGameEquipment private immutable _equipment;
    IWrapperFactory private immutable _wrapperFactory;
    IAssetsERC20Wrapper public immutable wrappedPTG;
    IUniswapV2Factory public immutable uniswapFactory;
    IUniswapV2Router02 public immutable uniswapRouter;

    constructor(
        address assetsContract,
        address equipmentContract,
        address wrapperFactoryContract,
        address uniswapFactoryContract,
        address uniswapRouterContract,
        uint256 ptgID
    ) {
        IWrapperFactory factory = IWrapperFactory(wrapperFactoryContract);
        _wrapperFactory = factory;
        _assets = IAssets(assetsContract);

        // you cannot call getWrapper here because you can't read from _wrapperFactory;
        address wrapperContract = factory.getWrapper(ptgID);
        require(wrapperContract != address(0), "invalid token wrapper");
        wrappedPTG = IAssetsERC20Wrapper(wrapperContract);

        uniswapFactory = IUniswapV2Factory(uniswapFactoryContract);
        uniswapRouter = IUniswapV2Router02(uniswapRouterContract);

        IAssetsERC20Wrapper(wrapperContract).approve(
            uniswapRouterContract,
            maxUint
        );
        _equipment = IGameEquipment(equipmentContract);
        _ptgID = ptgID;
    }

    function prices(uint itemID, uint quantity) external view returns (uint buy, uint sell) {
        address itemWrapper = _wrapperFactory.getWrapper(itemID);
        (uint ptgReserve, uint itemReserve) = UniswapV2Library.getReserves(address(uniswapFactory), address(wrappedPTG), itemWrapper);
        buy = 0;
        // do not error if trying to buy more than allowed, you can never buy *all* the items (because price would be infinite)
        if (itemReserve > quantity) {
            buy = UniswapV2Library.getAmountIn(quantity, ptgReserve, itemReserve);
        }
        sell = UniswapV2Library.getAmountOut(quantity, itemReserve, ptgReserve);
        return (buy,sell);
    }

    function wrapper(uint itemID) external view returns (address) {
        return _wrapperFactory.getWrapper(itemID);
    }

    function reserves(uint itemID) external view returns (uint ptg, uint item) {
        address itemWrapper = _wrapperFactory.getWrapper(itemID);
        return UniswapV2Library.getReserves(address(uniswapFactory), address(wrappedPTG), itemWrapper);
    }

    function bootstrap(
        uint256 tokenID,
        uint256 prestigeAmount,
        uint256 tokenAmount,
        string memory name,
        string memory symbol
    ) internal {
        // create the item proxy, and the liquidity pool
        // TODO: add to a list of items
        IAssetsERC20Wrapper tokenWrapper =
            IAssetsERC20Wrapper(
                _wrapperFactory.createWrapper(tokenID, name, symbol)
            );
        tokenWrapper.approve(address(uniswapRouter), maxUint);
        _assets.safeTransferFrom(
            address(this),
            address(tokenWrapper),
            tokenID,
            tokenAmount,
            ""
        );
        _assets.safeTransferFrom(
            address(this),
            address(wrappedPTG),
            _ptgID,
            prestigeAmount,
            ""
        );

        uniswapRouter.addLiquidity(
            address(wrappedPTG),
            address(tokenWrapper),
            prestigeAmount,
            tokenAmount,
            prestigeAmount,
            tokenAmount,
            address(this),
            maxUint
        );
        emit Bootstrap(tokenID, prestigeAmount, tokenAmount);
    }

    function getWrapper(uint256 tokenID)
        internal
        view
        returns (IAssetsERC20Wrapper)
    {
        address wrapperContract = _wrapperFactory.getWrapper(tokenID);
        require(wrapperContract != address(0), "invalid token wrapper");
        return IAssetsERC20Wrapper(wrapperContract);
    }

    function onMint(uint256 tokenID, uint256 amount) internal {
        // console.log('on mint');
        IAssetsERC20Wrapper tokenWrapper = getWrapper(tokenID);
        // console.log('wrapper: ', address(tokenWrapper));
        IUniswapV2Pair pair =
            IUniswapV2Pair(
                uniswapFactory.getPair(
                    address(tokenWrapper),
                    address(wrappedPTG)
                )
            );

        // console.log('pair: ', address(pair));
        // first we wrap them
        _assets.safeTransferFrom(
            address(this),
            address(tokenWrapper),
            tokenID,
            amount,
            ""
        );
                // console.log('wrapped');
        // then we transfer them to the liquidity contract
        tokenWrapper.transfer(address(pair), amount);
        // console.log('transferred to pair');
        // then we sync so no skim!
        pair.sync();
        // console.log('synced');
        emit Mint(tokenID, amount);
    }

    // onReceivedItem sells the item into the bonding curve
    function onReceivedItem(
        address from,
        uint256 tokenID,
        uint256 quantity,
        uint256 minAmountOut,
        uint256 deadline
    ) internal returns (uint256 amountReceived) {
        IAssetsERC20Wrapper tokenWrapper = getWrapper(tokenID);

        // first we wrap the item
        _assets.safeTransferFrom(
            address(this),
            address(tokenWrapper),
            tokenID,
            quantity,
            ""
        );
        // then we use the router
        address[] memory path = new address[](2);
        path[0] = address(tokenWrapper);
        path[1] = address(wrappedPTG);

        uint256[] memory amounts =
            uniswapRouter.swapExactTokensForTokens(
                quantity,
                minAmountOut,
                path,
                address(this),
                deadline
            );
        // now unwrap the PTG
        wrappedPTG.unwrap(address(this), from, amounts[1]);
        emit Sell(from, tokenID, amounts[0], quantity);
        return amounts[0];
    }

    // onReceivedItem buys an item with a max amount of PTG
    function onReceivedPTG(
        address from,
        uint256 amount,
        uint256 itemToBuy,
        uint256 quantity,
        uint256 maxAmount,
        uint256 deadline
    ) internal returns (uint256 amountReceived) {
        // console.log('on received ptg');
        IAssetsERC20Wrapper toBuyWrapper = getWrapper(itemToBuy);

        // first we wrap the ptg
        _assets.safeTransferFrom(
            address(this),
            address(wrappedPTG),
            _ptgID,
            amount,
            ""
        );
        // console.log('wrapped');

        // then we use the router
        address[] memory path = new address[](2);
        path[0] = address(wrappedPTG);
        path[1] = address(toBuyWrapper);

        // console.log('deadline, now', deadline, block.timestamp);

        uint256[] memory amounts =
            uniswapRouter.swapTokensForExactTokens(
                quantity,
                maxAmount,
                path,
                address(this),
                deadline
            );
        // console.log('swapped');
        // now unwrap the item
        toBuyWrapper.unwrap(address(this), from, quantity);
        // console.log('unwrapped');

        if (amounts[0] < amount) {
            wrappedPTG.unwrap(address(this), from, amount.sub(amounts[0]));
        }
        // console.log('emit');
        emit Buy(from, itemToBuy, amounts[0], quantity);
        return amounts[0];
    }

    function onERC1155Received(
        address operator,
        address from,
        uint256 id,
        uint256 value,
        bytes calldata data
    ) external override returns (bytes4) {
        uint256[] memory ids = new uint256[](1);
        uint256[] memory values = new uint256[](1);
        ids[0] = id;
        values[0] = value;
        onERC1155BatchReceived(operator, from, ids, values, data);
        return IERC1155Receiver.onERC1155Received.selector;
    }

    function onERC1155BatchReceived(
        address, //operator
        address from,
        uint256[] memory ids,
        uint256[] memory values,
        bytes calldata data
    ) public override returns (bytes4) {
        require(
            msg.sender == address(_assets),
            "Marketplace can only receive items from Assets contract"
        );
        // special case where we want to bootstrap and create a new pair
        if (bytes4(keccak256(abi.encodePacked(data))) == bootstrapSelector) {
            require(ids[0] == _ptgID, "first asset must be PTG");
            require(
                ids.length == 2,
                "pass in only PTG and a single other token"
            );
            IGameEquipment.EquipmentMetadata memory meta =
                _equipment.getMetadata(ids[1]);

            bootstrap(
                ids[1],
                values[0],
                values[1],
                meta.name,
                string(abi.encodePacked("CCWRAP-", uint2str(ids[1])))
            );
            return IERC1155Receiver.onERC1155BatchReceived.selector;
        }

        for (uint256 i; i < ids.length; i++) {
            if (from == address(0)) {
                // this is a mint
                onMint(ids[i], values[i]);
                continue;
            }
            if (ids[i] == _ptgID) {
                // this is a *purchase* of an item
                require(ids.length == 1, "cannot batch send more if purchasing");
                (uint256 tokenID, uint256 quantity, uint256 maxPrice, uint256 deadline) = abi.decode(data, (uint256, uint256, uint256, uint256));
                onReceivedPTG(from, values[i], tokenID, quantity, maxPrice, deadline);
                break;
            }
            (uint256 minAmountOut, uint256 deadline) = abi.decode(data, (uint256, uint256));
            onReceivedItem(from, ids[i], values[i], minAmountOut, deadline);
        }

        return IERC1155Receiver.onERC1155BatchReceived.selector;
    }

    function uint2str(uint256 _i)
        internal
        pure
        returns (string memory _uintAsString)
    {
        if (_i == 0) {
            return "0";
        }
        uint256 j = _i;
        uint256 len;
        while (j != 0) {
            len++;
            j /= 10;
        }
        bytes memory bstr = new bytes(len);
        uint256 k = len - 1;
        while (_i != 0) {
            bstr[k--] = bytes1(uint8(48 + (_i % 10)));
            _i /= 10;
        }
        return string(bstr);
    }
}

File 31 of 59 : IUniswapV2Factory.sol
pragma solidity >=0.5.0;

interface IUniswapV2Factory {
    event PairCreated(address indexed token0, address indexed token1, address pair, uint);

    function feeTo() external view returns (address);
    function feeToSetter() external view returns (address);

    function getPair(address tokenA, address tokenB) external view returns (address pair);
    function allPairs(uint) external view returns (address pair);
    function allPairsLength() external view returns (uint);

    function createPair(address tokenA, address tokenB) external returns (address pair);

    function setFeeTo(address) external;
    function setFeeToSetter(address) external;
}

File 32 of 59 : IUniswapV2Pair.sol
pragma solidity >=0.5.0;

interface IUniswapV2Pair {
    event Approval(address indexed owner, address indexed spender, uint value);
    event Transfer(address indexed from, address indexed to, uint value);

    function name() external pure returns (string memory);
    function symbol() external pure returns (string memory);
    function decimals() external pure returns (uint8);
    function totalSupply() external view returns (uint);
    function balanceOf(address owner) external view returns (uint);
    function allowance(address owner, address spender) external view returns (uint);

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

    function DOMAIN_SEPARATOR() external view returns (bytes32);
    function PERMIT_TYPEHASH() external pure returns (bytes32);
    function nonces(address owner) external view returns (uint);

    function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;

    event Mint(address indexed sender, uint amount0, uint amount1);
    event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
    event Swap(
        address indexed sender,
        uint amount0In,
        uint amount1In,
        uint amount0Out,
        uint amount1Out,
        address indexed to
    );
    event Sync(uint112 reserve0, uint112 reserve1);

    function MINIMUM_LIQUIDITY() external pure returns (uint);
    function factory() external view returns (address);
    function token0() external view returns (address);
    function token1() external view returns (address);
    function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
    function price0CumulativeLast() external view returns (uint);
    function price1CumulativeLast() external view returns (uint);
    function kLast() external view returns (uint);

    function mint(address to) external returns (uint liquidity);
    function burn(address to) external returns (uint amount0, uint amount1);
    function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
    function skim(address to) external;
    function sync() external;

    function initialize(address, address) external;
}

File 33 of 59 : IUniswapV2Router02.sol
pragma solidity >=0.6.2;

import './IUniswapV2Router01.sol';

interface IUniswapV2Router02 is IUniswapV2Router01 {
    function removeLiquidityETHSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external returns (uint amountETH);
    function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountETH);

    function swapExactTokensForTokensSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
    function swapExactETHForTokensSupportingFeeOnTransferTokens(
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external payable;
    function swapExactTokensForETHSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
}

File 34 of 59 : UniswapV2Library.sol
pragma solidity >=0.5.0;

// direct port of the uniswap library but with an upgraded SafeMath

import '@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol';
import "@openzeppelin/contracts/math/SafeMath.sol";

library UniswapV2Library {
    using SafeMath for uint;

    // returns sorted token addresses, used to handle return values from pairs sorted in this order
    function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) {
        require(tokenA != tokenB, 'UniswapV2Library: IDENTICAL_ADDRESSES');
        (token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
        require(token0 != address(0), 'UniswapV2Library: ZERO_ADDRESS');
    }

    // calculates the CREATE2 address for a pair without making any external calls
    function pairFor(address factory, address tokenA, address tokenB) internal pure returns (address pair) {
        (address token0, address token1) = sortTokens(tokenA, tokenB);
        pair = address(uint(keccak256(abi.encodePacked(
                hex'ff',
                factory,
                keccak256(abi.encodePacked(token0, token1)),
                hex'96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f' // init code hash
            ))));
    }

    // fetches and sorts the reserves for a pair
    function getReserves(address factory, address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) {
        (address token0,) = sortTokens(tokenA, tokenB);
        (uint reserve0, uint reserve1,) = IUniswapV2Pair(pairFor(factory, tokenA, tokenB)).getReserves();
        (reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0);
    }

    // given some amount of an asset and pair reserves, returns an equivalent amount of the other asset
    function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB) {
        require(amountA > 0, 'UniswapV2Library: INSUFFICIENT_AMOUNT');
        require(reserveA > 0 && reserveB > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
        amountB = amountA.mul(reserveB) / reserveA;
    }

    // given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset
    function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) {
        require(amountIn > 0, 'UniswapV2Library: INSUFFICIENT_INPUT_AMOUNT');
        require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
        uint amountInWithFee = amountIn.mul(997);
        uint numerator = amountInWithFee.mul(reserveOut);
        uint denominator = reserveIn.mul(1000).add(amountInWithFee);
        amountOut = numerator / denominator;
    }

    // given an output amount of an asset and pair reserves, returns a required input amount of the other asset
    function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn) {
        require(amountOut > 0, 'UniswapV2Library: INSUFFICIENT_OUTPUT_AMOUNT');
        require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
        uint numerator = reserveIn.mul(amountOut).mul(1000);
        uint denominator = reserveOut.sub(amountOut).mul(997);
        amountIn = (numerator / denominator).add(1);
    }

    // performs chained getAmountOut calculations on any number of pairs
    function getAmountsOut(address factory, uint amountIn, address[] memory path) internal view returns (uint[] memory amounts) {
        require(path.length >= 2, 'UniswapV2Library: INVALID_PATH');
        amounts = new uint[](path.length);
        amounts[0] = amountIn;
        for (uint i; i < path.length - 1; i++) {
            (uint reserveIn, uint reserveOut) = getReserves(factory, path[i], path[i + 1]);
            amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut);
        }
    }

    // performs chained getAmountIn calculations on any number of pairs
    function getAmountsIn(address factory, uint amountOut, address[] memory path) internal view returns (uint[] memory amounts) {
        require(path.length >= 2, 'UniswapV2Library: INVALID_PATH');
        amounts = new uint[](path.length);
        amounts[amounts.length - 1] = amountOut;
        for (uint i = path.length - 1; i > 0; i--) {
            (uint reserveIn, uint reserveOut) = getReserves(factory, path[i - 1], path[i]);
            amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut);
        }
    }
}

File 35 of 59 : IAssetsERC20Wrapper.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0;

import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC1155/ERC1155Receiver.sol";
import "./IAssets.sol";

import "hardhat/console.sol";

interface IAssetsERC20Wrapper is IERC20 {

    function unwrap(address account, address to, uint256 amount) external;
    
}

File 36 of 59 : IUniswapV2Router01.sol
pragma solidity >=0.6.2;

interface IUniswapV2Router01 {
    function factory() external pure returns (address);
    function WETH() external pure returns (address);

    function addLiquidity(
        address tokenA,
        address tokenB,
        uint amountADesired,
        uint amountBDesired,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB, uint liquidity);
    function addLiquidityETH(
        address token,
        uint amountTokenDesired,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external payable returns (uint amountToken, uint amountETH, uint liquidity);
    function removeLiquidity(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB);
    function removeLiquidityETH(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external returns (uint amountToken, uint amountETH);
    function removeLiquidityWithPermit(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountA, uint amountB);
    function removeLiquidityETHWithPermit(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountToken, uint amountETH);
    function swapExactTokensForTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);
    function swapTokensForExactTokens(
        uint amountOut,
        uint amountInMax,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);
    function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        payable
        returns (uint[] memory amounts);
    function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
        external
        returns (uint[] memory amounts);
    function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        returns (uint[] memory amounts);
    function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
        external
        payable
        returns (uint[] memory amounts);

    function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
    function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
    function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn);
    function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
    function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
}

File 37 of 59 : IERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

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

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

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

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

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

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

    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

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

File 38 of 59 : WrappedPTG.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0;

import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC1155/ERC1155Receiver.sol";
import "./interfaces/IAssets.sol";
import "./interfaces/IAssetsERC20Wrapper.sol";

import "hardhat/console.sol";

// turns out the regular wrapper factory doesn't support name, but this does.

contract WrappedPTG is IAssetsERC20Wrapper, ERC20, ERC1155Receiver {
    using SafeMath for uint256;

    IAssets immutable _tokenHolder;
    uint256 private _tokenID; // the specific token id this erc20 is wrapping

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

    constructor(address holder, uint256 prestigeID)
        ERC20("Wrapped Prestige", "wPTG")
    {
        _tokenHolder = IAssets(holder);
        _tokenID = prestigeID; // initialize the contract for the copy
    }

    function unwrap(
        address account,
        address to,
        uint256 amount
    ) external override {
        if (account != _msgSender()) {
            uint256 currentAllowance = allowance(account, _msgSender());
            require(
                currentAllowance >= amount,
                "AssetsERC20Wrapper: unwrap amount exceeds allowance"
            );
            _approve(account, _msgSender(), currentAllowance.sub(amount));
        }
        _burn(account, amount);
        _tokenHolder.safeTransferFrom(address(this), to, _tokenID, amount, "");
    }

    function onERC1155Received(
        address, // operator
        address from,
        uint256 id,
        uint256 value,
        bytes calldata // data
    ) external override returns (bytes4) {
        require(
            msg.sender == address(_tokenHolder),
            "AssetsERC20Wrapper#onERC1155: invalid asset address"
        );
        require(id == _tokenID, "AssetsERC20Wrapper: invalid token id");

        _mint(from, value);

        return IERC1155Receiver.onERC1155Received.selector;
    }

    function onERC1155BatchReceived(
        address,
        address,
        uint256[] memory,
        uint256[] memory,
        bytes calldata
    ) public pure override returns (bytes4) {
        revert("batch send is not supported");
    }
}

File 39 of 59 : ERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "../../GSN/Context.sol";
import "./IERC20.sol";
import "../../math/SafeMath.sol";

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

    mapping (address => uint256) private _balances;

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

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;
    uint8 private _decimals;

    /**
     * @dev Sets the values for {name} and {symbol}, initializes {decimals} with
     * a default value of 18.
     *
     * To select a different value for {decimals}, use {_setupDecimals}.
     *
     * All three of these values are immutable: they can only be set once during
     * construction.
     */
    constructor (string memory name_, string memory symbol_) public {
        _name = name_;
        _symbol = symbol_;
        _decimals = 18;
    }

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

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

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

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

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

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

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

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

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

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

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

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

        _beforeTokenTransfer(sender, recipient, amount);

        _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
        _balances[recipient] = _balances[recipient].add(amount);
        emit Transfer(sender, recipient, amount);
    }

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

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

        _totalSupply = _totalSupply.add(amount);
        _balances[account] = _balances[account].add(amount);
        emit Transfer(address(0), account, amount);
    }

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

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

        _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
        _totalSupply = _totalSupply.sub(amount);
        emit Transfer(account, address(0), amount);
    }

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

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

    /**
     * @dev Sets {decimals} to a value other than the default one of 18.
     *
     * WARNING: This function should only be called from the constructor. Most
     * applications that interact with token contracts will not expect
     * {decimals} to ever change, and may work incorrectly if it does.
     */
    function _setupDecimals(uint8 decimals_) internal {
        _decimals = decimals_;
    }

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

File 40 of 59 : VendingMachine.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.4;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "./interfaces/IAssets.sol";
import "./meta/EIP712MetaTransaction.sol";
import "@openzeppelin/contracts/token/ERC1155/ERC1155Receiver.sol";

import "hardhat/console.sol";

/**
This is a contract that sells Assets (equipment). Right now it just mints them without any care about the total supply.
Next feature after would be maintaining rarity.

You register an asset for sale, it will then mint and transfer an asset to the sender
 */
contract VendingMachine is Ownable, EIP712MetaTransaction, ERC1155Receiver {
    using SafeMath for uint256;

    uint256 private immutable _prestigeID; // id of the prestige token
    IAssets public immutable assets;

    event ItemForSale(uint256 indexed id, uint256 indexed price);
    event ItemRemoved(uint256 indexed id);

    mapping(uint256 => uint256) public itemsForSale; // mapping of assetId to price

    constructor(address assetsAddress, uint256 prestigeID)
        public
        EIP712MetaTransaction("VendingMachine", "1")
    {
        _prestigeID = prestigeID;
        assets = IAssets(assetsAddress);
    }

    function sellItem(uint id, uint price) external onlyOwner {
      itemsForSale[id] = price;
      emit ItemForSale(id, price);
    }

    function stopSellingItem(uint id) external onlyOwner {
      delete itemsForSale[id];
      emit ItemRemoved(id);
    }

    function onERC1155Received(
        address operator,
        address from,
        uint256 id,
        uint256 value,
        bytes calldata data // abi.encoded (uint256 itemID)
    ) external override returns (bytes4) {
        require(
            msg.sender == address(assets),
            "VendingMachine#onERC1155BatchReceived: invalid asset address"
        );
        require(id == _prestigeID, "VendingMachine#OnlySupportsPrestige");
        uint256 itemId = abi.decode(data, (uint256));
        uint256 price = itemsForSale[itemId];
        require(price > 0, "VendingMachine#ItemNotForSale");
        require(value == price, "VendingMachine#NotEnoughPrestige");

        // if it is enough then mint it and send it
        require(assets.forge(from, itemId, 1, ""), "VendingMachine#ForgeFailed");

        return IERC1155Receiver.onERC1155Received.selector;
    }

    function onERC1155BatchReceived(
        address,
        address from,
        uint256[] memory ids,
        uint256[] memory values,
        bytes calldata data
    ) public override returns (bytes4) {
        revert("Batch not supported");
    }

    function _msgSender()
        internal
        view
        override(Context, EIP712MetaTransaction)
        returns (address payable)
    {
        return EIP712MetaTransaction.msgSender();
    }
}

File 41 of 59 : Faction.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.4;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/math/Math.sol";
import "@openzeppelin/contracts/token/ERC1155/ERC1155Receiver.sol";
import "@openzeppelin/contracts/utils/EnumerableSet.sol";
import "./interfaces/IAssets.sol";
import "./interfaces/IRegisterableAsset.sol";
import "./EnumerableMap.sol";
import "./EnumerableStringMap.sol";
import "./Constants.sol";

import "hardhat/console.sol";

contract Faction is IRegisterableAsset, ERC1155Receiver {
  using SafeMath for uint256;
  using EnumerableMap for EnumerableMap.Map;
  using EnumerableStringMap for EnumerableStringMap.Map;
  using EnumerableSet for EnumerableSet.UintSet;

  bytes32 constant ASSET_NAME = "faction";
  uint256 constant TOTAL_SUPPLY = 2**24;

  uint256 constant ASSET_DECIMALS = 10**18;

  IAssets immutable public assets;

  // A little oddly but these are stored as the id +1 which is why this is private
  // this allows us to check for existence by looking at 0 which otherwise we could not (since 0 is a valid token id)
  mapping(string => uint256) private _byName; // name => id of token + 1

  struct Metadata {
    string name;
    EnumerableMap.Map properties;
    EnumerableStringMap.Map extendedProperties;
  }

  mapping(uint256 => Metadata) private _metadata;

  mapping(uint256 => EnumerableSet.UintSet) private _inventory;

  mapping(uint256 => mapping(uint256 => uint256)) private _balances;

  constructor(address assetsAddress) {
    assets = IAssets(assetsAddress);
  }

  function byName(string calldata name) public view returns (uint id) {
    id = _byName[name];
    if (id == 0) {
      return id;
    }
    return id - 1;
  }

  function assetName() override public pure returns (bytes32) {
    return ASSET_NAME;
  }

  function assetTotalSupply() override public pure returns (uint256) {
    return TOTAL_SUPPLY;
  }

  function assetIsNFT() override public pure returns (bool) {
    return true;
  }

  function assetOperators() override public view returns (address[] memory) {
    address[] memory operators = new address[](1);
    operators[0] = address(this);
    return operators;
  }

  function idRange() public view returns (uint256, uint256) {
    return assets.idRange(ASSET_NAME);
  }

  function mint(
    address account,
    string calldata name,
    EnumerableMap.MapEntry[] calldata properties,
    EnumerableStringMap.MapEntry[] calldata extendedProperties
  ) external returns (uint256) {
    require(_byName[name] == 0, "Name already taken");

    uint256[] memory ids = assets.mint(account, ASSET_NAME, 1, "");
    uint256 id = ids[0];

    Metadata storage metadata = _metadata[id];
    metadata.name = name;

    EnumerableMap.Map storage _properties = metadata.properties;
    EnumerableStringMap.Map storage _extendedProperties = metadata.extendedProperties;

    for (uint i; i < properties.length; i++) {
      _properties.set(properties[i].key, properties[i].value);
    }

    for (uint i; i < extendedProperties.length; i++) {
      _extendedProperties.set(extendedProperties[i].key, extendedProperties[i].value);
    }

    _properties.set("createdAt", bytes32(block.timestamp));

    _byName[name] = id + 1;

    return id;
  }

  function exists(
    uint256 id
  ) public view returns (bool) {
    return assets.exists(ASSET_NAME, id);
  }

  function name(
    uint256 id
  ) external view returns (string memory) {
    return _metadata[id].name;
  }

  function prestige(
    uint256 id
  ) external view returns (uint256) {
    (uint256 prestigeTokenID,) = assets.idRange(Constants.prestigeAssetName());
    return _balances[id][prestigeTokenID];
  }

  function properties(
    uint256 id
  ) external view returns (EnumerableMap.MapEntry[] memory) {
    EnumerableMap.Map storage _properties = _metadata[id].properties;
    uint256 propsLength = _properties.length(); 
    EnumerableMap.MapEntry[] memory propertyPairs = new EnumerableMap.MapEntry[](propsLength);
    for (uint256 i = 0; i < propsLength; i++) {
      (bytes32 k, bytes32 v) = _properties.at(i);
      propertyPairs[i] = EnumerableMap.MapEntry({
        key: k,
        value: v
      });
    }
    return propertyPairs;
  }

  function getProperty(
    uint256 id,
    bytes32 key
  ) external view returns (bytes32) {
    return _metadata[id].properties.get(key);
  }
  
  function extendedProperties(
    uint256 id
  ) external view returns (EnumerableStringMap.MapEntry[] memory) {
    EnumerableStringMap.Map storage _extendedProperties = _metadata[id].extendedProperties;
    uint256 propsLength = _extendedProperties.length(); 
    EnumerableStringMap.MapEntry[] memory propertyPairs = new EnumerableStringMap.MapEntry[](propsLength);
    for (uint256 i = 0; i < propsLength; i++) {
      (bytes32 k, string memory v) = _extendedProperties.at(i);
      propertyPairs[i] = EnumerableStringMap.MapEntry({
        key: k,
        value: v
      });
    }
    return propertyPairs;
  }

  function getExtendedProperty(
    uint256 id,
    bytes32 key
  ) external view returns (string memory) {
    return _metadata[id].extendedProperties.get(key);
  }

  function inventory(
    uint256 id
  ) external view returns (uint256[] memory) {
    EnumerableSet.UintSet storage set = _inventory[id];
    uint256[] memory ids = new uint256[](set.length());
    for (uint256 i = 0; i < ids.length; i++) {
      ids[i] = set.at(i);
    }
    return ids;
  }

  function balances(
    uint256 id
  ) external view returns (uint256[] memory) {
    EnumerableSet.UintSet storage set = _inventory[id];
    uint256[] memory ret = new uint256[](set.length());
    for (uint256 i = 0; i < ret.length; i++) {
      ret[i] = _balances[id][set.at(i)];
    }
    return ret;
  }

  function balanceOf(
    uint256 id,
    uint256 tokenID
  ) external view returns (uint256) {
    return _balances[id][tokenID];
  }

  function onERC1155Received(
    address operator,
    address from,
    uint256 id,
    uint256 value,
    bytes calldata data
  ) external override returns(bytes4) {
    uint256[] memory ids = new uint256[](1);
    uint256[] memory values = new uint256[](1);
    ids[0] = id;
    values[0] = value;
    onERC1155BatchReceived(operator, from, ids, values, data);
    return IERC1155Receiver.onERC1155Received.selector;
  }

  function onERC1155BatchReceived(
    address operator,
    address from,
    uint256[] memory ids,
    uint256[] memory values,
    bytes calldata data // abi.encoded (uint256 gladiatorID)
  ) public override returns(bytes4) {
    require(msg.sender == address(assets), "Gladiator can only receive items from Assets contract");

    (uint256 gladiatorID) = abi.decode(data, (uint256));
    require(exists(gladiatorID), "gladiator does not exist");

    EnumerableSet.UintSet storage gladiatorInventory = _inventory[gladiatorID];
    for (uint i = 0; i < ids.length; i++) {
      gladiatorInventory.add(ids[i]);
      _balances[gladiatorID][ids[i]] += values[i];
    }

    return IERC1155Receiver.onERC1155BatchReceived.selector;
  }
}

File 42 of 59 : DiceRoller.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.4;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/math/Math.sol";
import "./Constants.sol";
import "./interfaces/IDiceRolls.sol";

import "hardhat/console.sol";

contract DiceRoller is
    IDiceRolls,
    Ownable
{
    using SafeMath for uint256;

    uint256 public override latest;

    mapping(uint256 => RollParams) public rolls;

    function roll(uint256 random, PerformancePair[] calldata performance)
        public
        override
        onlyOwner
    {
        // console.log("---- dice roll");
        RollParams storage roll = rolls[latest + 1];
        roll.random = uint256(
            keccak256(abi.encodePacked(random, blockhash(block.number - 1)))
        );
        // console.log('pushing performances');
        for (uint256 i; i < performance.length; i++) {
            roll.performances.push(performance[i]);
        }
        roll.id = latest + 1;
        roll.blockNumber = block.number;
        latest++;
        emit DiceRoll(latest, roll.random);
    }

    function getLatestRoll() public view override returns (RollParams memory) {
        return getRoll(latest);
    }

    function getRoll(uint256 index)
        public
        view
        override
        returns (RollParams memory)
    {
        return rolls[index];
    }

    function getRange(uint256 start, uint256 last)
        public
        view
        override
        returns (RollParams[] memory)
    {
        // console.log("getRange:", start, last, latest);
        RollParams[] memory rolls_ = new RollParams[](last - start + 1);
        uint256 returnedRollsIndex;
        for (uint256 i = start; i <= last; i++) {
            // console.log('getRange add', i, 'random', rolls[i].random);
            rolls_[returnedRollsIndex] = rolls[i];
            returnedRollsIndex++;
        }
        return rolls_;
    }
}

File 43 of 59 : TournamentV4.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.4;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/math/Math.sol";
import "./Assets.sol";
import "./Trophy.sol";
import "./Gladiator.sol";
import "./interfaces/IRegisterableAsset.sol";
import "./Constants.sol";
import "./interfaces/IGameLogicV4.sol";
import "./interfaces/IDiceRolls.sol";
import "./interfaces/ITournamentV4.sol";

import "hardhat/console.sol";

contract TournamentV4 is
    ITournamentV4,
    Ownable,
    IRegisterableAsset
{
    using SafeMath for uint256;

    bytes32 constant ASSET_NAME = "TournamentV4";
    uint256 constant TOTAL_SUPPLY = 2**38;
    uint256 constant ASSET_DECIMALS = 10**18;

    bytes32 constant HIT_POINTS = "hitpoints";
    bytes32 constant ATTACK = "attack";
    bytes32 constant DEFENSE = "defense";
    bytes32 constant NAME = "name";

    mapping(uint256 => TournamentData) private _tournaments;

    Assets private immutable _assets; // ERC-1155 Assets contract
    Gladiator private immutable _gladiator; // gladiator transfers
    Trophy public immutable trophies; // trophies minting

    bytes32 private immutable _gladiatorAssetName; 

    modifier onlyApproved(uint256 tournamentId) {
        require(
            _assets.isApprovedOrOwner(_msgSender(), _msgSender(), tournamentId),
            "Tournament: not an owner of the tournament"
        );
        _;
    }

    constructor(address _assetsAddress, address _gladiatorAddress) {
        require(
            _assetsAddress != address(0),
            "Tournament#constructor: INVALID_INPUT _assetsAddress is 0"
        );
        _assets = Assets(_assetsAddress);
        _gladiator = Gladiator(_gladiatorAddress);
        trophies = new Trophy(_assetsAddress, bytes32("TrophyV4"));
        _gladiatorAssetName = Gladiator(_gladiatorAddress).assetName();
    }

    function assetName() public pure override returns (bytes32) {
        return ASSET_NAME;
    }

    function assetTotalSupply() public pure override returns (uint256) {
        return TOTAL_SUPPLY;
    }

    function assetIsNFT() public pure override returns (bool) {
        return true;
    }

    function assetOperators() public view override returns (address[] memory) {
        address[] memory operators = new address[](1);
        operators[0] = address(this);
        return operators;
    }

    function idRange() public view returns (uint256, uint256) {
        return _assets.idRange(ASSET_NAME);
    }

    function newTournament(
        string memory name,
        address gameLogic_,
        address roller_,
        uint8 totalRounds,
        uint256 notBefore,
        string[] memory factions
    ) public onlyOwner returns (uint256) {
        require(
            factions.length <= 65536,
            "Tournament#newTournament: Can only have 65536 factions"
        );

        address creator = _msgSender();

        uint256[] memory ids = _assets.mint(creator, ASSET_NAME, 1, "");
        uint256 tournamentId = ids[0];

        TournamentData storage tournament = _tournaments[tournamentId];
        tournament.name = name;
        tournament.creator = creator;
        tournament.totalRounds = totalRounds;
        tournament.factions = factions;
        tournament.gameLogic = IGameLogicV4(gameLogic_);
        tournament.notBefore = notBefore;
        tournament.roller = IDiceRolls(roller_);
        emit NewTournament(creator, notBefore, tournamentId);
        return tournamentId;
    }

    function registerGladiator(TournamentData storage tournament, uint tournamentId, uint id, uint16 faction) internal {
        require(
            faction < tournament.factions.length,
            "Tournament#onERC1155BatchReceived: faction does not exist"
        );
        require(_assets.exists(_gladiatorAssetName, id), "Tournament#Not a gladiator");

        tournament.registrations.push(
            Registration({gladiator: id, faction: faction})
        );
        emit RegistrationEvent(
            tournamentId,
            id,
            faction,
            tournament.registrations.length - 1
        );
    }

    function registerGladiators(uint tournamentId, uint[] calldata ids, uint16[] calldata factions) onlyOwner public {
        TournamentData storage tournament = _tournaments[tournamentId];

        require(
            tournament.totalRounds > 0,
            "Tournament#onERC1155BatchReceived: tournament does not exist"
        );
        require(
            !started(tournamentId),
            "Tournament#onERC1155BatchReceived: tournament already started"
        );
        require(
            tournament.registrations.length + ids.length <= this.maxGladiators(tournamentId),
            "Tournament#onERC1155BatchReceived: registration closed"
        );

        for (uint i; i < ids.length; i++) {
            registerGladiator(tournament, tournamentId, ids[i], factions[i]);
        }
    }

    function name(uint256 tournamentId) external view returns (string memory) {
        return _tournaments[tournamentId].name;
    }

    function firstRoll(uint256 tournamentId)
        external
        view
        override
        returns (uint256)
    {
        return _tournaments[tournamentId].firstRoll;
    }

    function notBefore(uint256 tournamentId)
        external
        view
        override
        returns (uint256)
    {
        return _tournaments[tournamentId].notBefore;
    }

    function lastRoll(uint256 tournamentId)
        external
        view
        override
        returns (uint256)
    {
        return _tournaments[tournamentId].lastRoll;
    }

    function roller(uint256 tournamentId)
        external
        view
        override
        returns (IDiceRolls)
    {
        return _tournaments[tournamentId].roller;
    }

    function started(uint256 tournamentId) public override view returns (bool) {
        TournamentData storage tournament = _tournaments[tournamentId];
        // console.log('first role', tournament.firstRoll, 'latest', latest);
        uint256 _firstRoll = tournament.firstRoll;
        return _firstRoll > 0 && _firstRoll <= tournament.roller.latest();
    }

    function totalRounds(uint256 tournamentId) external view returns (uint256) {
        return _tournaments[tournamentId].totalRounds;
    }

    function maxGladiators(uint256 tournamentId)
        external
        view
        returns (uint256)
    {
        return 2**uint256(_tournaments[tournamentId].totalRounds);
    }

    function registrationCount(uint256 tournamentId)
        external
        view
        returns (uint256)
    {
        return _tournaments[tournamentId].registrations.length;
    }

    function registration(uint256 tournamentId, uint256 registrationId)
        external
        view
        returns (Registration memory)
    {
        return _tournaments[tournamentId].registrations[registrationId];
    }

    function registrations(uint256 tournamentId)
        external
        view
        override
        returns (Registration[] memory)
    {
        TournamentData storage tournament = _tournaments[tournamentId];
        return tournament.registrations;
    }

    function factions(uint256 tournamentId)
        external
        view
        returns (string[] memory)
    {
        TournamentData storage tournament = _tournaments[tournamentId];
        return tournament.factions;
    }

    function start(uint256 tournamentId) external {
        TournamentData storage tournament = _tournaments[tournamentId];
        require(
            block.timestamp > tournament.notBefore,
            "Tournament cannot start yet"
        );
        tournament.firstRoll = tournament.roller.latest().add(1);
    }

    function checkpoint(uint256 tournamentId) external {
        TournamentData storage tournament = _tournaments[tournamentId];

        (uint256 winner, uint256 tournamentLastRoll) =
            tournament.gameLogic.tournamentWinner(tournamentId);

        tournament.lastRoll = tournamentLastRoll;

        createTrophy(tournamentId, tournament, winner);
    }

    function createTrophy(
        uint256 tournamentId,
        TournamentData storage tournament,
        uint256 winnerId
    ) internal {
        Registration memory winner = tournament.registrations[winnerId];

        uint256 trophyId =
            trophies.mint(
                address(_gladiator),
                tournament.name,
                tournamentId,
                winner.gladiator
            );

        _assets.mint(
            address(_gladiator),
            Constants.prestigeAssetName(),
            10 * ASSET_DECIMALS,
            abi.encodePacked(winner.gladiator)
        );

        tournament.champion.faction = winner.faction;
        tournament.champion.gladiator = winner.gladiator;
        tournament.champion.trophy = trophyId;

        emit TournamentComplete(tournamentId, winner.gladiator);
    }

    function getChampion(uint256 tournamentId)
        public
        view
        returns (Champion memory)
    {
        TournamentData storage tournament = _tournaments[tournamentId];
        require(tournament.lastRoll > 0, "Tournament is still in progress");
        return tournament.champion;
    }
}

File 44 of 59 : Trophy.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.4;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "./interfaces/IAssets.sol";
import "./interfaces/IRegisterableAsset.sol";
import "./EnumerableMap.sol";
import "./meta/EIP712MetaTransaction.sol";

import "hardhat/console.sol";

contract Trophy is Ownable, IRegisterableAsset, EIP712MetaTransaction {
  using SafeMath for uint256;
  using EnumerableMap for EnumerableMap.Map;

  bytes32 immutable ASSET_NAME;
  uint256 constant TOTAL_SUPPLY = 2**38;

  IAssets immutable public assets;

  struct Metadata {
    string name;
    EnumerableMap.Map properties;
  }

  mapping(uint256 => Metadata) private _metadata;

  constructor(
    address assetsAddress,
    bytes32 name
   ) public EIP712MetaTransaction("Trophy", "1") {
    assets = IAssets(assetsAddress);
    ASSET_NAME = name;
  }

  function assetName() override public view returns (bytes32) {
    return ASSET_NAME;
  }

  function assetTotalSupply() override public pure returns (uint256) {
    return TOTAL_SUPPLY;
  }

  function assetIsNFT() override public pure returns (bool) {
    return true;
  }

  function assetOperators() override public view returns (address[] memory) {
    address[] memory operators = new address[](1);
    operators[0] = address(this);
    return operators;
  }

  function idRange() public view returns (uint256, uint256) {
    return assets.idRange(ASSET_NAME);
  }

  function mint(
    address account,
    string  memory name,
    uint256 tournamentID,
    uint256 gladiatorID
  ) external onlyOwner returns (uint256) {
    uint256[] memory ids = assets.mint(account, ASSET_NAME, 1, abi.encodePacked(gladiatorID));
    uint256 id = ids[0];

    Metadata storage metadata = _metadata[id];
    metadata.name = name;
 
    EnumerableMap.Map storage _properties = metadata.properties;

    _properties.set("tournamentID", bytes32(tournamentID));
    _properties.set("gladiatorID", bytes32(gladiatorID));
    _properties.set("createdAt", bytes32(block.timestamp));

    return id;
  }

  function exists(
    uint256 id
  ) external view returns (bool) {
    return assets.exists(ASSET_NAME, id);
  }

  function name(
    uint256 id
  ) external view returns (string memory) {
    return _metadata[id].name;
  }

  function properties(
    uint256 id
  ) external view returns (EnumerableMap.MapEntry[] memory) {
    EnumerableMap.Map storage _properties = _metadata[id].properties;
    uint256 propsLength = _properties.length(); 
    EnumerableMap.MapEntry[] memory propertyPairs = new EnumerableMap.MapEntry[](propsLength);
    for (uint256 i = 0; i < propsLength; i++) {
      (bytes32 k, bytes32 v) = _properties.at(i);
      propertyPairs[i].key = k;
      propertyPairs[i].value = v;
    }
    return propertyPairs;
  }

  function getProperty(
    uint256 id,
    bytes32 key
  ) external view returns (bytes32) {
    EnumerableMap.Map storage _properties = _metadata[id].properties;
    return _properties.get(key);
  }

  function _msgSender() internal view override(Context,EIP712MetaTransaction) returns (address payable) {
    return EIP712MetaTransaction.msgSender();
  }
}

File 45 of 59 : BettingPoolV5.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.4;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/math/Math.sol";
import "@openzeppelin/contracts/token/ERC1155/ERC1155Receiver.sol";
import "./meta/EIP712MetaTransaction.sol";
import "./Assets.sol";
import "./TournamentV4.sol";
import "./Constants.sol";

import "hardhat/console.sol";

// only calling this with the 5 because otherwise there's a build error conflicting with BettingPoolV4
interface IFaction5 {
    function byName(string calldata name) external returns (uint);
}

contract BettingPoolV5 is ERC1155Receiver, Ownable, EIP712MetaTransaction {
  using SafeMath for uint256;

  event BetPlaced(address indexed better, uint indexed tournamentId, uint indexed gladiatorId);

  uint256 constant private oneHundredPercent = 10**10;

  Assets immutable private _assets; // ERC-1155 Assets contract
  TournamentV4 immutable private _tournaments; // ERC-1155 Assets contract
  IFaction5 immutable private _faction;
  address immutable private _gladiatorContract;

  uint immutable private _prestigeId;

  uint8 public multiplier;
  uint8 public gladiatorPercent;

  mapping(uint256 => mapping(address => mapping(uint => uint))) public betsByUser;  //tournamentID => user => gladiator => amount
  mapping(uint256 => mapping(address => uint8)) public betCountByUser; // tournamentID => user => count; // only allow 2 bets per user
  mapping(uint256 => mapping(uint => uint)) public betsByGladiator; // tournamentID => gladiatorId => totalAmount
  mapping(uint256 => uint) public betsByTournament; // tournamentID => totalAmount

  mapping(uint256 => uint256) public incentivesByTournament; // tournamentID => amount of incentive

  mapping(uint256 => bool) private _claimedByGladiator; // tournamentID => true/false if already claimed by gladiator

  constructor(
    address _assetsAddress,
    address _tournamentAddress,
    address _gladiatorAddress,
    address _factionAddress
  ) EIP712MetaTransaction("BettingPool", "2") {
    require(
      _assetsAddress != address(0),
      "BettingPool#constructor: INVALID_INPUT _assetsAddress is 0"
    );
    Assets assetContract = Assets(_assetsAddress);
    _assets = assetContract;
    _tournaments = TournamentV4(_tournamentAddress);
    (uint start,) = assetContract.idRange(Constants.prestigeAssetName());
    _prestigeId = start;
    gladiatorPercent = 20;
    _gladiatorContract = _gladiatorAddress;
    _faction = IFaction5(_factionAddress);
  }

  function setIncentive(uint256 tournamentId, uint256 amount) external onlyOwner {
    incentivesByTournament[tournamentId] = amount;
  }

  function setGladiatorPercent(uint8 percent) external onlyOwner {
    gladiatorPercent = percent;
  }

  function expectedWinnings(uint tournamentId, address user, uint champion) public view returns (uint) {
    uint bet = betsByUser[tournamentId][user][champion];
    if (bet == 0) {
      return 0;
    }

    // calculate their percentage of all the *winners* of the tournament (those that picked the right gladiator)
    // percent calculated as 10 digits (10^10 is 100%);
    uint percentOfPool = (bet * oneHundredPercent).div(betsByGladiator[tournamentId][champion]);
    
    return betsByTournament[tournamentId].sub(gladiatorWinnings(tournamentId)).add(incentivesByTournament[tournamentId]).mul(percentOfPool).div(oneHundredPercent);
  }

  function withdraw(uint tournamentId) external returns (bool) {
    TournamentV4.Champion memory winner = _tournaments.getChampion(tournamentId);
    uint champion = winner.gladiator;

    address user = msgSender();

    uint winnings = expectedWinnings(tournamentId, user, champion);
    require(winnings > 0, "BettingPool#You didn't win");
    
    delete betsByUser[tournamentId][user][champion];
    delete betCountByUser[tournamentId][user];
    _assets.safeTransferFrom(address(this), user, _prestigeId, winnings, '');
    return true;
  }

  function gladiatorWinnings(uint tournamentId) internal view returns (uint) {
    return betsByTournament[tournamentId].mul(gladiatorPercent).div(100);
  }

  function claimForGladiator(uint tournamentId) external returns (bool) {
    require(!_claimedByGladiator[tournamentId], "Gladiators winnings already claimed");
    TournamentV4.Champion memory winner = _tournaments.getChampion(tournamentId);

    string memory factionName = _tournaments.factions(tournamentId)[winner.faction];
    uint factionID = _faction.byName(factionName);
    
    uint winnings = gladiatorWinnings(tournamentId);

    if (factionID > 0) {
      uint factionWinnings = winnings.mul(25).div(100);
      _assets.safeTransferFrom(address(this), address(_faction), _prestigeId, winnings, abi.encode(factionID));
      winnings = winnings.sub(factionWinnings);
    }

    // console.log('winnings', winnings);
    _claimedByGladiator[tournamentId] = true;
    _assets.safeTransferFrom(address(this), _gladiatorContract, _prestigeId, winnings, abi.encode(winner.gladiator));
    return true;
  }

  function migrate(address payable newAddress) external onlyOwner {
    // move all ptg to the new address and destroy this contract
    uint balance = _assets.balanceOf(address(this), _prestigeId);
    _assets.safeTransferFrom(address(this), newAddress, _prestigeId, balance, '');
    selfdestruct(newAddress);
  }

  function onERC1155Received(
    address, // operator
    address from,
    uint256 id,
    uint256 value,
    bytes calldata data
  ) external override returns(bytes4) {
    require(msg.sender == address(_assets), "BettingPool#onERC1155Received: invalid asset address");
    require(id == _prestigeId, "BettingPool#Invalid token send");
    if (from == address(0)) {
      // this is a MINT so just accept it
      return IERC1155Receiver.onERC1155Received.selector;
    }
    (uint256 tournamentId, uint256 gladiatorId) = abi.decode(data, (uint256, uint256));
    // console.log("bet!", tournamentId, gladiatorId, from);
    require(!_tournaments.started(tournamentId), "BettingPool#Tournament already started");

    // if this is a *new* bet on the tournament then increase the count
    // but allow unlimited increases in your betting;
    if (betsByUser[tournamentId][from][gladiatorId] == 0) {
      require(betCountByUser[tournamentId][from] < 2, "BettingPool#Too many bets");
      betCountByUser[tournamentId][from] += 1; 
    }
    betsByUser[tournamentId][from][gladiatorId] += value;
    betsByGladiator[tournamentId][gladiatorId] += value;
    betsByTournament[tournamentId] += value;
    
    emit BetPlaced(from, tournamentId, gladiatorId);

    return IERC1155Receiver.onERC1155Received.selector;
  }

  function onERC1155BatchReceived(
    address,
    address,
    uint256[] memory,
    uint256[] memory,
    bytes calldata
  ) pure public override returns(bytes4) {
      revert("BettingPool#No batch allowed");
  }

  function _msgSender() internal view override(Context,EIP712MetaTransaction) returns (address payable) {
    return EIP712MetaTransaction.msgSender();
  }
}

File 46 of 59 : Equipment.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.4;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "./interfaces/IAssets.sol";
import "./interfaces/IRegisterableAsset.sol";
import "./EnumerableMap.sol";
import "./meta/EIP712MetaTransaction.sol";
import "./interfaces/IGameEquipment.sol";

import "hardhat/console.sol";

contract Equipment is Ownable, IRegisterableAsset, IGameEquipment, EIP712MetaTransaction {
    using SafeMath for uint256;
    using EnumerableMap for EnumerableMap.Map;

    bytes32 constant ASSET_NAME = "equipment";
    uint256 constant TOTAL_SUPPLY = 2**40;

    IAssets public immutable assets;

    mapping(uint256 => EquipmentMetadata) public metadata;

    constructor(address assetsAddress)
        public
        EIP712MetaTransaction("Equipment", "1")
    {
        assets = IAssets(assetsAddress);
    }

    function assetName() public view override returns (bytes32) {
        return ASSET_NAME;
    }

    function assetTotalSupply() public pure override returns (uint256) {
        return TOTAL_SUPPLY;
    }

    function assetIsNFT() public pure override returns (bool) {
        return true;
    }

    function assetOperators() public view override returns (address[] memory) {
        address[] memory operators = new address[](2);
        operators[0] = address(this);
        operators[1] = owner();
        return operators;
    }

    function idRange() public view returns (uint256, uint256) {
        return assets.idRange(ASSET_NAME);
    }

    function getMetadata(uint id) public override view returns (EquipmentMetadata memory equipment) {
        equipment = metadata[id];
        equipment.id = id;
        return equipment;
    }

    function mint(
        address account,
        string memory name,
        int256 hitPoints,
        int256 attack,
        int256 defense,
        uint256 percentChanceOfUse,
        uint256 numberOfUsesPerGame
    ) external onlyOwner returns (uint256) {
        uint256[] memory ids = assets.mint(account, ASSET_NAME, 1, "");
        uint256 id = ids[0];

        EquipmentMetadata storage metadata = metadata[id];
        metadata.name = name;
        metadata.hitPoints = hitPoints;
        metadata.attack = attack;
        metadata.defense = defense;
        metadata.percentChanceOfUse = percentChanceOfUse;
        metadata.numberOfUsesPerGame = numberOfUsesPerGame;
        metadata.createdAt = bytes32(block.timestamp);

        return id;
    }

    function exists(uint256 id) external view returns (bool) {
        return assets.exists(ASSET_NAME, id);
    }

    function _msgSender()
        internal
        view
        override(Context, EIP712MetaTransaction)
        returns (address payable)
    {
        return EIP712MetaTransaction.msgSender();
    }
}

File 47 of 59 : TournamentLogger.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.4;
pragma experimental ABIEncoderV2;
import "@openzeppelin/contracts/utils/EnumerableSet.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract TournamentLogger is Ownable {
    using EnumerableSet for EnumerableSet.UintSet;

    EnumerableSet.UintSet private tournaments;

    function add(uint tournamentId) public onlyOwner {
        tournaments.add(tournamentId);
    }

    function all() public view returns (uint[] memory ids) {
        uint len = tournaments.length();
        ids = new uint[](len);
        for (uint i; i < len; i++) {
            ids[i] = tournaments.at(i);
        }
        return ids;
    }

    function length() public view returns (uint) {
        return tournaments.length();
    }

    function slice(uint start, uint length) public view returns (uint[] memory ids) {
        ids = new uint[](length);
        uint idsIndx = 0;
        for (uint i = start; i < start + length; i++) {
            ids[idsIndx] = tournaments.at(i);
            idsIndx++;
        }
        return ids;
    }
    
}

File 48 of 59 : AccessControl.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "../utils/EnumerableSet.sol";
import "../utils/Address.sol";
import "../GSN/Context.sol";

/**
 * @dev Contract module that allows children to implement role-based access
 * control mechanisms.
 *
 * Roles are referred to by their `bytes32` identifier. These should be exposed
 * in the external API and be unique. The best way to achieve this is by
 * using `public constant` hash digests:
 *
 * ```
 * bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
 * ```
 *
 * Roles can be used to represent a set of permissions. To restrict access to a
 * function call, use {hasRole}:
 *
 * ```
 * function foo() public {
 *     require(hasRole(MY_ROLE, msg.sender));
 *     ...
 * }
 * ```
 *
 * Roles can be granted and revoked dynamically via the {grantRole} and
 * {revokeRole} functions. Each role has an associated admin role, and only
 * accounts that have a role's admin role can call {grantRole} and {revokeRole}.
 *
 * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
 * that only accounts with this role will be able to grant or revoke other
 * roles. More complex role relationships can be created by using
 * {_setRoleAdmin}.
 *
 * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
 * grant and revoke this role. Extra precautions should be taken to secure
 * accounts that have been granted it.
 */
abstract contract AccessControl is Context {
    using EnumerableSet for EnumerableSet.AddressSet;
    using Address for address;

    struct RoleData {
        EnumerableSet.AddressSet members;
        bytes32 adminRole;
    }

    mapping (bytes32 => RoleData) private _roles;

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

    /**
     * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
     *
     * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
     * {RoleAdminChanged} not being emitted signaling this.
     *
     * _Available since v3.1._
     */
    event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);

    /**
     * @dev Emitted when `account` is granted `role`.
     *
     * `sender` is the account that originated the contract call, an admin role
     * bearer except when using {_setupRole}.
     */
    event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Emitted when `account` is revoked `role`.
     *
     * `sender` is the account that originated the contract call:
     *   - if using `revokeRole`, it is the admin role bearer
     *   - if using `renounceRole`, it is the role bearer (i.e. `account`)
     */
    event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) public view returns (bool) {
        return _roles[role].members.contains(account);
    }

    /**
     * @dev Returns the number of accounts that have `role`. Can be used
     * together with {getRoleMember} to enumerate all bearers of a role.
     */
    function getRoleMemberCount(bytes32 role) public view returns (uint256) {
        return _roles[role].members.length();
    }

    /**
     * @dev Returns one of the accounts that have `role`. `index` must be a
     * value between 0 and {getRoleMemberCount}, non-inclusive.
     *
     * Role bearers are not sorted in any particular way, and their ordering may
     * change at any point.
     *
     * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
     * you perform all queries on the same block. See the following
     * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
     * for more information.
     */
    function getRoleMember(bytes32 role, uint256 index) public view returns (address) {
        return _roles[role].members.at(index);
    }

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) public view returns (bytes32) {
        return _roles[role].adminRole;
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function grantRole(bytes32 role, address account) public virtual {
        require(hasRole(_roles[role].adminRole, _msgSender()), "AccessControl: sender must be an admin to grant");

        _grantRole(role, account);
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function revokeRole(bytes32 role, address account) public virtual {
        require(hasRole(_roles[role].adminRole, _msgSender()), "AccessControl: sender must be an admin to revoke");

        _revokeRole(role, account);
    }

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been granted `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `account`.
     */
    function renounceRole(bytes32 role, address account) public virtual {
        require(account == _msgSender(), "AccessControl: can only renounce roles for self");

        _revokeRole(role, account);
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event. Note that unlike {grantRole}, this function doesn't perform any
     * checks on the calling account.
     *
     * [WARNING]
     * ====
     * This function should only be called from the constructor when setting
     * up the initial roles for the system.
     *
     * Using this function in any other way is effectively circumventing the admin
     * system imposed by {AccessControl}.
     * ====
     */
    function _setupRole(bytes32 role, address account) internal virtual {
        _grantRole(role, account);
    }

    /**
     * @dev Sets `adminRole` as ``role``'s admin role.
     *
     * Emits a {RoleAdminChanged} event.
     */
    function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
        emit RoleAdminChanged(role, _roles[role].adminRole, adminRole);
        _roles[role].adminRole = adminRole;
    }

    function _grantRole(bytes32 role, address account) private {
        if (_roles[role].members.add(account)) {
            emit RoleGranted(role, account, _msgSender());
        }
    }

    function _revokeRole(bytes32 role, address account) private {
        if (_roles[role].members.remove(account)) {
            emit RoleRevoked(role, account, _msgSender());
        }
    }
}

File 49 of 59 : SafeERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "./IERC20.sol";
import "../../math/SafeMath.sol";
import "../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using SafeMath for uint256;
    using Address for address;

    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(IERC20 token, address spender, uint256 value) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        // solhint-disable-next-line max-line-length
        require((value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 newAllowance = token.allowance(address(this), spender).add(value);
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero");
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        if (returndata.length > 0) { // Return data is optional
            // solhint-disable-next-line max-line-length
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}

File 50 of 59 : Bundler.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.4;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC1155/IERC1155MetadataURI.sol";
import "@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol";
import "@openzeppelin/contracts/introspection/ERC165.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/utils/EnumerableSet.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";

contract Bundler is
    IERC1155,
    IERC1155MetadataURI,
    ERC165,
    AccessControl,
    IERC1155Receiver
{
    using EnumerableSet for EnumerableSet.UintSet;
    using EnumerableSet for EnumerableSet.AddressSet;
    using SafeMath for uint256;
    using Address for address;
    using Counters for Counters.Counter;
    using SafeERC20 for IERC20;

    Counters.Counter private _tokenIds;

    bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");

    struct TokenMetadata {
        string uri;
        EnumerableSet.AddressSet addresses;
        mapping(address => EnumerableSet.UintSet) ids;
        mapping(address => mapping(uint256 => uint256)) balances;
    }

    mapping(uint256 => TokenMetadata) private _tokenMetadata;

    function uri(uint256 tokenID)
        external
        view
        override
        returns (string memory)
    {
        return _tokenMetadata[tokenID].uri;
    }

    mapping(address => EnumerableSet.UintSet) private _addressTokens; // the tokens an address holds

    // Mapping from token ID to account balances
    mapping(uint256 => mapping(address => uint256)) private _balances;

    // Mapping from account to operator approvals
    mapping(address => mapping(address => bool)) private _operatorApprovals;

    /*
     *     bytes4(keccak256('balanceOf(address,uint256)')) == 0x00fdd58e
     *     bytes4(keccak256('balanceOfBatch(address[],uint256[])')) == 0x4e1273f4
     *     bytes4(keccak256('setApprovalForAll(address,bool)')) == 0xa22cb465
     *     bytes4(keccak256('isApprovedForAll(address,address)')) == 0xe985e9c5
     *     bytes4(keccak256('safeTransferFrom(address,address,uint256,uint256,bytes)')) == 0xf242432a
     *     bytes4(keccak256('safeBatchTransferFrom(address,address,uint256[],uint256[],bytes)')) == 0x2eb2c2d6
     *
     *     => 0x00fdd58e ^ 0x4e1273f4 ^ 0xa22cb465 ^
     *        0xe985e9c5 ^ 0xf242432a ^ 0x2eb2c2d6 == 0xd9b67a26
     */
    bytes4 private constant _INTERFACE_ID_ERC1155 = 0xd9b67a26;

    /*
     *     bytes4(keccak256('uri(uint256)')) == 0x0e89341c
     */
    bytes4 private constant _INTERFACE_ID_ERC1155_METADATA_URI = 0x0e89341c;

    constructor() public {
        // register the supported interfaces to conform to ERC1155 via ERC165
        _registerInterface(_INTERFACE_ID_ERC1155);

        // register the supported interfaces to conform to ERC1155MetadataURI via ERC165
        _registerInterface(_INTERFACE_ID_ERC1155_METADATA_URI);
        _setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
        _setupRole(MINTER_ROLE, _msgSender());
    }

     function contractURI() public view returns (string memory) {
        return "https://arena.cryptocolosseum.com/metadata/bundler.json";
    }

    function mint(address account, string calldata uri)
        public
        returns (uint256 id)
    {
        require(hasRole(MINTER_ROLE, _msgSender()), "Caller is not a minter");

        _tokenIds.increment();
        id = _tokenIds.current();
        _mint(account, id, 1, "");
        TokenMetadata storage metadata = _tokenMetadata[id];
        metadata.uri = uri;
        return id;
    }

    function bundledAddresses(uint tokenID) public view returns (address[] memory addresses) {
        EnumerableSet.AddressSet storage tokenAddresses = _tokenMetadata[tokenID].addresses;
        uint256 len = tokenAddresses.length();
        addresses = new address[](len);
        for (uint i; i < len; i++) {
            addresses[i] = tokenAddresses.at(i);
        }
        return addresses;
    }

    function bundledIds(uint tokenID, address addr) public view returns (uint[] memory ids) {
        EnumerableSet.UintSet storage heldIDs = _tokenMetadata[tokenID].ids[addr];
        uint256 len = heldIDs.length();
        ids = new uint[](len);
        for (uint i; i < len; i++) {
            ids[i] = heldIDs.at(i);
        }
        return ids;
    }

    function unbundleAndBurn(uint256 tokenID, address to) public {
        // todo: gas efficiency
        EnumerableSet.AddressSet storage tokenAddresses = _tokenMetadata[tokenID].addresses;
        uint256 addrLen = tokenAddresses.length();
        for (uint i; i < addrLen; i++) {
            address addr = tokenAddresses.at(i);
            uint256[] memory ids = bundledIds(tokenID, addr);
            for (uint j; j < ids.length; j++) {
                withdraw(tokenID, addr, ids[j], to);
            }
        }
        burn(tokenID);
    }

    function burn(uint256 tokenID) public {
        require(balanceOf(_msgSender(), tokenID) > 0, "No token");
        _burn(_msgSender(), tokenID, 1);
    }

    function withdraw(
        uint256 tokenID,
        address addr,
        uint256 id,
        address to
    ) public {
        require(balanceOf(_msgSender(), tokenID) > 0, "No token");
        TokenMetadata storage metadata = _tokenMetadata[tokenID];
        uint256 amount = metadata.balances[addr][id];
        delete metadata.balances[addr][id];
        metadata.addresses.remove(addr);
        metadata.ids[addr].remove(id);
        IERC1155(addr).safeTransferFrom(address(this), to, id, amount, '');
    }

    function tokenBalance(
        uint256 tokenID,
        address addr,
        uint256 id
    ) public view returns (uint256) {
        TokenMetadata storage metadata = _tokenMetadata[tokenID];
        return metadata.balances[addr][id];
    }

    function addressTokens(address addr) public view returns (uint256[] memory ids) {
        EnumerableSet.UintSet storage tokens = _addressTokens[addr];
        uint256 len = tokens.length();
        ids = new uint256[](len);
        for (uint i; i < len; i++) {
            ids[i] = tokens.at(i);
        }
        return ids;
    }

    function onERC1155Received(
        address, // operator
        address,
        uint256 id,
        uint256 value,
        bytes calldata data // the id of the token
    ) external override returns (bytes4) {
        TokenMetadata storage metadata =
            _tokenMetadata[abi.decode(data, (uint256))];
        address sender = msg.sender;
        metadata.addresses.add(sender);
        metadata.ids[sender].add(id);
        metadata.balances[sender][id] = metadata.balances[sender][id].add(
            value
        );
        return IERC1155Receiver.onERC1155Received.selector;
    }

    function onERC1155BatchReceived(
        address,
        address,
        uint256[] memory,
        uint256[] memory,
        bytes calldata
    ) public pure override returns (bytes4) {
        revert("batch send is not supported");
    }

    function _beforeTokenTransfer(
        address operator,
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) internal {
        for (uint i; i < ids.length; i++) {
            if (from != address(0)) {
                _addressTokens[from].remove(ids[i]);
            }
            if (to != address(0)) {
                _addressTokens[to].add(ids[i]);
            }
        }
    }

    // below is boiler plate from open zeppelin ERC1155

    /**
     * @dev See {IERC1155-balanceOf}.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     */
    function balanceOf(address account, uint256 id)
        public
        view
        override
        returns (uint256)
    {
        require(
            account != address(0),
            "ERC1155: balance query for the zero address"
        );
        return _balances[id][account];
    }

    /**
     * @dev See {IERC1155-balanceOfBatch}.
     *
     * Requirements:
     *
     * - `accounts` and `ids` must have the same length.
     */
    function balanceOfBatch(address[] memory accounts, uint256[] memory ids)
        public
        view
        override
        returns (uint256[] memory)
    {
        require(
            accounts.length == ids.length,
            "ERC1155: accounts and ids length mismatch"
        );

        uint256[] memory batchBalances = new uint256[](accounts.length);

        for (uint256 i = 0; i < accounts.length; ++i) {
            require(
                accounts[i] != address(0),
                "ERC1155: batch balance query for the zero address"
            );
            batchBalances[i] = _balances[ids[i]][accounts[i]];
        }

        return batchBalances;
    }

    /**
     * @dev See {IERC1155-setApprovalForAll}.
     */
    function setApprovalForAll(address operator, bool approved)
        public
        virtual
        override
    {
        require(
            _msgSender() != operator,
            "ERC1155: setting approval status for self"
        );

        _operatorApprovals[_msgSender()][operator] = approved;
        emit ApprovalForAll(_msgSender(), operator, approved);
    }

    /**
     * @dev See {IERC1155-isApprovedForAll}.
     */
    function isApprovedForAll(address account, address operator)
        public
        view
        override
        returns (bool)
    {
        return _operatorApprovals[account][operator];
    }

    /**
     * @dev See {IERC1155-safeTransferFrom}.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 id,
        uint256 amount,
        bytes memory data
    ) public virtual override {
        require(to != address(0), "ERC1155: transfer to the zero address");
        require(
            from == _msgSender() || isApprovedForAll(from, _msgSender()),
            "ERC1155: caller is not owner nor approved"
        );

        address operator = _msgSender();

        _beforeTokenTransfer(
            operator,
            from,
            to,
            _asSingletonArray(id),
            _asSingletonArray(amount),
            data
        );

        _balances[id][from] = _balances[id][from].sub(
            amount,
            "ERC1155: insufficient balance for transfer"
        );
        _balances[id][to] = _balances[id][to].add(amount);

        emit TransferSingle(operator, from, to, id, amount);

        _doSafeTransferAcceptanceCheck(operator, from, to, id, amount, data);
    }

    /**
     * @dev See {IERC1155-safeBatchTransferFrom}.
     */
    function safeBatchTransferFrom(
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) public virtual override {
        require(
            ids.length == amounts.length,
            "ERC1155: ids and amounts length mismatch"
        );
        require(to != address(0), "ERC1155: transfer to the zero address");
        require(
            from == _msgSender() || isApprovedForAll(from, _msgSender()),
            "ERC1155: transfer caller is not owner nor approved"
        );

        address operator = _msgSender();

        _beforeTokenTransfer(operator, from, to, ids, amounts, data);

        for (uint256 i = 0; i < ids.length; ++i) {
            uint256 id = ids[i];
            uint256 amount = amounts[i];

            _balances[id][from] = _balances[id][from].sub(
                amount,
                "ERC1155: insufficient balance for transfer"
            );
            _balances[id][to] = _balances[id][to].add(amount);
        }

        emit TransferBatch(operator, from, to, ids, amounts);

        _doSafeBatchTransferAcceptanceCheck(
            operator,
            from,
            to,
            ids,
            amounts,
            data
        );
    }

    /**
     * @dev Creates `amount` tokens of token type `id`, and assigns them to `account`.
     *
     * Emits a {TransferSingle} event.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
     * acceptance magic value.
     */
    function _mint(
        address account,
        uint256 id,
        uint256 amount,
        bytes memory data
    ) internal virtual {
        require(account != address(0), "ERC1155: mint to the zero address");

        address operator = _msgSender();

        _beforeTokenTransfer(
            operator,
            address(0),
            account,
            _asSingletonArray(id),
            _asSingletonArray(amount),
            data
        );

        _balances[id][account] = _balances[id][account].add(amount);
        emit TransferSingle(operator, address(0), account, id, amount);

        _doSafeTransferAcceptanceCheck(
            operator,
            address(0),
            account,
            id,
            amount,
            data
        );
    }

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_mint}.
     *
     * 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 _mintBatch(
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) internal virtual {
        require(to != address(0), "ERC1155: mint to the zero address");
        require(
            ids.length == amounts.length,
            "ERC1155: ids and amounts length mismatch"
        );

        address operator = _msgSender();

        _beforeTokenTransfer(operator, address(0), to, ids, amounts, data);

        for (uint256 i = 0; i < ids.length; i++) {
            _balances[ids[i]][to] = amounts[i].add(_balances[ids[i]][to]);
        }

        emit TransferBatch(operator, address(0), to, ids, amounts);

        _doSafeBatchTransferAcceptanceCheck(
            operator,
            address(0),
            to,
            ids,
            amounts,
            data
        );
    }

    /**
     * @dev Destroys `amount` tokens of token type `id` from `account`
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     * - `account` must have at least `amount` tokens of token type `id`.
     */
    function _burn(
        address account,
        uint256 id,
        uint256 amount
    ) internal virtual {
        require(account != address(0), "ERC1155: burn from the zero address");

        address operator = _msgSender();

        _beforeTokenTransfer(
            operator,
            account,
            address(0),
            _asSingletonArray(id),
            _asSingletonArray(amount),
            ""
        );

        _balances[id][account] = _balances[id][account].sub(
            amount,
            "ERC1155: burn amount exceeds balance"
        );

        emit TransferSingle(operator, account, address(0), id, amount);
    }

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_burn}.
     *
     * Requirements:
     *
     * - `ids` and `amounts` must have the same length.
     */
    function _burnBatch(
        address account,
        uint256[] memory ids,
        uint256[] memory amounts
    ) internal virtual {
        require(account != address(0), "ERC1155: burn from the zero address");
        require(
            ids.length == amounts.length,
            "ERC1155: ids and amounts length mismatch"
        );

        address operator = _msgSender();

        _beforeTokenTransfer(operator, account, address(0), ids, amounts, "");

        for (uint256 i = 0; i < ids.length; i++) {
            _balances[ids[i]][account] = _balances[ids[i]][account].sub(
                amounts[i],
                "ERC1155: burn amount exceeds balance"
            );
        }

        emit TransferBatch(operator, account, address(0), ids, amounts);
    }

    /**
     * @dev Hook that is called before any token transfer. This includes minting
     * and burning, as well as batched variants.
     *
     * The same hook is called on both single and batched variants. For single
     * transfers, the length of the `id` and `amount` arrays will be 1.
     *
     * Calling conditions (for each `id` and `amount` pair):
     *
     * - When `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * of token type `id` will be  transferred to `to`.
     * - When `from` is zero, `amount` tokens of token type `id` will be minted
     * for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens of token type `id`
     * will be burned.
     * - `from` and `to` are never both zero.
     * - `ids` and `amounts` have the same, non-zero length.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    // function _beforeTokenTransfer(
    //     address operator,
    //     address from,
    //     address to,
    //     uint256[] memory ids,
    //     uint256[] memory amounts,
    //     bytes memory data
    // ) internal virtual {}

    function _doSafeTransferAcceptanceCheck(
        address operator,
        address from,
        address to,
        uint256 id,
        uint256 amount,
        bytes memory data
    ) private {
        if (to.isContract()) {
            try
                IERC1155Receiver(to).onERC1155Received(
                    operator,
                    from,
                    id,
                    amount,
                    data
                )
            returns (bytes4 response) {
                if (
                    response != IERC1155Receiver(to).onERC1155Received.selector
                ) {
                    revert("ERC1155: ERC1155Receiver rejected tokens");
                }
            } catch Error(string memory reason) {
                revert(reason);
            } catch {
                revert("ERC1155: transfer to non ERC1155Receiver implementer");
            }
        }
    }

    function _doSafeBatchTransferAcceptanceCheck(
        address operator,
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) private {
        if (to.isContract()) {
            try
                IERC1155Receiver(to).onERC1155BatchReceived(
                    operator,
                    from,
                    ids,
                    amounts,
                    data
                )
            returns (bytes4 response) {
                if (
                    response !=
                    IERC1155Receiver(to).onERC1155BatchReceived.selector
                ) {
                    revert("ERC1155: ERC1155Receiver rejected tokens");
                }
            } catch Error(string memory reason) {
                revert(reason);
            } catch {
                revert("ERC1155: transfer to non ERC1155Receiver implementer");
            }
        }
    }

    function _asSingletonArray(uint256 element)
        private
        pure
        returns (uint256[] memory)
    {
        uint256[] memory array = new uint256[](1);
        array[0] = element;

        return array;
    }
}

File 51 of 59 : Counters.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "../math/SafeMath.sol";

/**
 * @title Counters
 * @author Matt Condon (@shrugs)
 * @dev Provides counters that can only be incremented or decremented by one. This can be used e.g. to track the number
 * of elements in a mapping, issuing ERC721 ids, or counting request ids.
 *
 * Include with `using Counters for Counters.Counter;`
 * Since it is not possible to overflow a 256 bit integer with increments of one, `increment` can skip the {SafeMath}
 * overflow check, thereby saving gas. This does assume however correct usage, in that the underlying `_value` is never
 * directly accessed.
 */
library Counters {
    using SafeMath for uint256;

    struct Counter {
        // This variable should never be directly accessed by users of the library: interactions must be restricted to
        // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add
        // this feature: see https://github.com/ethereum/solidity/issues/4637
        uint256 _value; // default: 0
    }

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

    function increment(Counter storage counter) internal {
        // The {SafeMath} overflow check can be skipped here, see the comment at the top
        counter._value += 1;
    }

    function decrement(Counter storage counter) internal {
        counter._value = counter._value.sub(1);
    }
}

File 52 of 59 : Auction.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.4;
pragma experimental ABIEncoderV2;

import "./Assets.sol";
import "./interfaces/IAuction.sol";
import "@openzeppelin/contracts/token/ERC1155/ERC1155Receiver.sol";
import "@openzeppelin/contracts/utils/Counters.sol";

contract Auction is IAuction, ERC1155Receiver {
    using Counters for Counters.Counter;

    Assets private immutable _assets; // ERC-1155 Assets contract
    uint256 private immutable _ptgID;
    bytes32 constant EQUIPMENT_NAME = "equipment";

    mapping(uint256 => AuctionData) public auctions;

    Counters.Counter public tokenIds;

    constructor(address assetsContract, uint256 ptgId) {
        _assets = Assets(assetsContract);
        _ptgID = ptgId;
    }

    function newAuction(
        address _owner,
        uint256 _startTime,
        uint256 _endTime,
        uint256 _itemId,
        uint256 _minBidAmount,
        uint256 _minIncrement
    ) private returns (uint256 id) {
        require(_owner != address(0), "Owner must be specifed");

        tokenIds.increment();
        uint256 auctionId = tokenIds.current();

        AuctionData storage auction = auctions[auctionId];

        auction.id = auctionId;
        auction.owner = _owner;
        auction.startTime = _startTime;
        auction.endTime = _endTime;
        auction.itemId = _itemId;
        auction.minBidAmount = _minBidAmount;
        auction.minIncrement = _minIncrement;

        emit NewAuction(_owner, _startTime, _endTime, auctionId, _minBidAmount);

        return auctionId;
    }

    function placeBid(
        address from,
        uint256 value,
        bytes calldata data // abi encoded (uint256 auctionId)
    ) private {
        // reject payments of 0 PTG
        require(value != 0, "Cannot bid 0");

        uint256 auctionId = abi.decode(data, (uint256));

        AuctionData storage auction = auctions[auctionId];

        require(from != auction.owner, "Owner cannot place bid");
        require(!auction.canceled, "cancelled");
        require(block.timestamp < auction.endTime, "already ended");
        require(block.timestamp > auction.startTime, "not started");

        // calculate the user's total bid based on the current amount they've sent to the contract
        // plus whatever has been sent with this transaction
        uint256 newBid = auction.fundsByBidder[from] + value;
        uint256 highestAuctionBid =
            auction.fundsByBidder[auction.highestBidder];

        require(
            newBid >= auction.minBidAmount,
            "Cannot bid below minimum amount"
        );

        require(
            newBid >= highestAuctionBid + auction.minIncrement,
            "New bid is less than minimum highest bid"
        );

        auction.fundsByBidder[from] = newBid;
        auction.bidders.push(Bid({bidder: from, amount: newBid, time: block.timestamp}));

        if (from != auction.highestBidder) {
            auction.highestBidder = from;
        }

        emit NewBid(
            from,
            auction.id,
            newBid,
            auction.highestBidder,
            highestAuctionBid
        );
    }

    function initiateTransfer(
        address to,
        uint256 tokenID,
        uint256 amount
    ) private returns (bool success) {
        _assets.safeTransferFrom(address(this), to, tokenID, amount, "");
        return true;
    }

    function claimItem(uint256 auctionId) public returns (bool success) {
        AuctionData storage auction = auctions[auctionId];
        require(!auction.highestBidderHasWithdrawn, "already withdrawn");
        require(
            auction.canceled || (block.timestamp > auction.endTime),
            "must be over or canceled"
        );
        // if the auction is over with no bidders or it is canceled then reclaim the 
        // item for the owner.
        if (
            auction.canceled ||
            (block.timestamp > auction.endTime &&
            auction.highestBidder == address(0))
        ) {
            auction.highestBidderHasWithdrawn = true;
            initiateTransfer(auction.owner, auction.itemId, 1);
            return true;
        }

        // otherwise send the item to the highest bidder
        auction.highestBidderHasWithdrawn = true;
        initiateTransfer(auction.highestBidder, auction.itemId, 1);
        return true;
    }

    function claimPayment(uint256 auctionId) public returns (bool success) {
        AuctionData storage auction = auctions[auctionId];
        require(
            block.timestamp > auction.endTime,
            "Can't withdraw before auction ends"
        );
        require(!auction.ownerHasWithdrawn, "already withdrawn");
        auction.ownerHasWithdrawn = true;

        initiateTransfer(auction.owner, _ptgID, auction.fundsByBidder[auction.highestBidder]);
        return true;
    }

    function withdraw(address bidder, uint256 auctionId) public returns (bool success) {
        AuctionData storage auction = auctions[auctionId];
        require(
            bidder != auction.highestBidder,
            "highest bidder may not withdraw"
        );

        require(bidder == msg.sender || block.timestamp > auction.endTime, "only the bidder can withdraw before the auction is over");

        uint256 funds = auction.fundsByBidder[bidder];
        require(funds > 0, "no bids");
        delete auction.fundsByBidder[bidder];
        initiateTransfer(bidder, _ptgID, funds);

        return true;
    }

    function getAuctionBidders(uint256 auctionId)
        public
        view
        returns (Bid[] memory bidders)
    {
        // return auctions[auctionId];
        return auctions[auctionId].bidders;
    }

    function getBidAmount(uint256 auctionId, address bidderAddress)
        public
        view
        returns (uint256 amount)
    {
        return auctions[auctionId].fundsByBidder[bidderAddress];
    }

    function highestBidAmount(uint256 auctionId)
        public
        view
        returns (uint256 amount)
    {
        AuctionData storage auction = auctions[auctionId];
        return auction.fundsByBidder[auction.highestBidder];
    }

    function cancelAuction(uint256 auctionId) public returns (bool success) {
        AuctionData storage auction = auctions[auctionId];

        require(msg.sender == auction.owner, "Not owner");
        require(block.timestamp < auction.startTime, "already started");
        require(!auction.canceled, "already canceled");

        auction.canceled = true;
        emit AuctionCancelled();
        return true;
    }

    function handleItemReceived(
        address from,
        uint256 id,
        uint256 value,
        bytes calldata data // abi encoded (uint256 startTime, uint256 endTime)
    ) internal returns (bool) {
        require(
            value == 1,
            "Auction#onERC1155Received: may only add one auction at a time"
        );

        (
            uint256 startTime,
            uint256 endTime,
            uint256 minBidAmount,
            uint256 minIncrement
        ) = abi.decode(data, (uint256, uint256, uint256, uint256));

        newAuction(from, startTime, endTime, id, minBidAmount, minIncrement);
        return true;
    }

    function onERC1155Received(
        address,
        address from,
        uint256 id,
        uint256 value,
        bytes calldata data
    ) external override returns (bytes4) {
        require(
            msg.sender == address(_assets),
            "Auction#onERC1155Received: invalid asset address"
        );
        if (id == _ptgID) {
            placeBid(from, value, data);
        } else {
            require(handleItemReceived(from, id, value, data), "failed");
        }
        return IERC1155Receiver.onERC1155Received.selector;
    }

    function onERC1155BatchReceived(
        address, //operator
        address,
        uint256[] memory,
        uint256[] memory,
        bytes calldata
    ) public override returns (bytes4) {
        revert("batch auction creation not supported");
    }
}

File 53 of 59 : IAuction.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.4;
pragma experimental ABIEncoderV2;

import "./IDiceRolls.sol";

interface IAuction {
    event NewBid(
        address indexed bidder,
        uint256 indexed auctionId,
        uint256 bid,
        address highestBidder,
        uint256 highestBid
    );
    event AuctionCancelled();

    event NewAuction(
        address indexed owner,
        uint256 indexed startTime,
        uint256 indexed endTime,
        uint256 auctionId,
        uint256 minBidAmount
    );

    struct Bid {
        address bidder;
        uint256 amount;
        uint256 time;
    }

    struct AuctionData {
        // static
        uint256 id;
        address owner;
        uint256 itemId;
        uint256 startTime;
        uint256 endTime;
        uint256 minBidAmount;
        uint256 minIncrement;
        // state
        bool canceled;
        address highestBidder;
        Bid[] bidders;
        mapping(address => uint256) fundsByBidder;
        bool ownerHasWithdrawn;
        bool highestBidderHasWithdrawn;
    }
}

File 54 of 59 : BettingPoolV4.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.4;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/math/Math.sol";
import "@openzeppelin/contracts/token/ERC1155/ERC1155Receiver.sol";
import "./meta/EIP712MetaTransaction.sol";
import "./Assets.sol";
import "./TournamentV4.sol";
import "./Constants.sol";

import "hardhat/console.sol";

interface IFaction {
    function byName(string calldata name) external returns (uint);
}

contract BettingPoolV4 is ERC1155Receiver, Ownable, EIP712MetaTransaction {
  using SafeMath for uint256;

  event BetPlaced(address indexed better, uint indexed tournamentId, uint indexed gladiatorId);

  Assets immutable private _assets; // ERC-1155 Assets contract
  TournamentV4 immutable private _tournaments; // ERC-1155 Assets contract
  IFaction immutable private _faction;
  address immutable private _gladiatorContract;

  uint immutable private _prestigeId;

  uint8 public multiplier;
  uint8 public gladiatorPercent;

  mapping(uint256 => mapping(address => mapping(uint => uint))) public betsByUser;  //tournamentID => user => gladiator => amount
  mapping(uint256 => mapping(uint => uint)) public betsByGladiator; // tournamentID => gladiatorId => totalAmount
  mapping(uint256 => uint) public betsByTournament; // tournamentID => totalAmount

  mapping(uint256 => bool) private _claimedByGladiator; // tournamentID => true/false if already claimed by gladiator

  constructor(
    address _assetsAddress,
    address _tournamentAddress,
    address _gladiatorAddress,
    address _factionAddress
  ) public EIP712MetaTransaction("BettingPool", "1") {
    require(
      _assetsAddress != address(0),
      "BettingPool#constructor: INVALID_INPUT _assetsAddress is 0"
    );
    Assets assetContract = Assets(_assetsAddress);
    _assets = assetContract;
    _tournaments = TournamentV4(_tournamentAddress);
    (uint start,) = assetContract.idRange(Constants.prestigeAssetName());
    _prestigeId = start;
    gladiatorPercent = 20;
    _gladiatorContract = _gladiatorAddress;
    _faction = IFaction(_factionAddress);
  }

  function setMultiplier(uint8 multiplier_) external onlyOwner {
    multiplier = multiplier_;
  }

  function setGladiatorPercent(uint8 percent) external onlyOwner {
    gladiatorPercent = percent;
  }

  function expectedWinnings(uint tournamentId, address user, uint champion) public view returns (uint) {
    uint bet = betsByUser[tournamentId][user][champion];
    if (bet == 0) {
      return 0;
    }
    uint winningPool = betsByGladiator[tournamentId][champion];

    // percent calculated as 10 digits (10^10 is 100%);
    uint percentOfPool = (bet * 10**10).div(winningPool);
    
    uint winnings = betsByTournament[tournamentId].sub(gladiatorWinnings(tournamentId)).mul(percentOfPool).div(10**10);

    if (multiplier > 0) {
      // mint the multiplier for this winner
      winnings *= uint(multiplier);
    }
    return winnings;
  }

  function withdraw(uint tournamentId) external returns (bool) {
    TournamentV4.Champion memory winner = _tournaments.getChampion(tournamentId);
    uint champion = winner.gladiator;

    address user = msgSender();

    uint winnings = expectedWinnings(tournamentId, user, champion);
    require(winnings > 0, "BettingPool#You didn't win");
    
    delete betsByUser[tournamentId][user][champion];
    _assets.mint(address(this), Constants.prestigeAssetName(), winnings, '');
    _assets.safeTransferFrom(address(this), user, _prestigeId, winnings, '');
    return true;
  }

  function gladiatorWinnings(uint tournamentId) internal view returns (uint) {
    return betsByTournament[tournamentId].mul(gladiatorPercent).div(100);
  }

  function claimForGladiator(uint tournamentId) external returns (bool) {
    require(!_claimedByGladiator[tournamentId], "Gladiators winnings already claimed");
    TournamentV4.Champion memory winner = _tournaments.getChampion(tournamentId);

    string memory factionName = _tournaments.factions(tournamentId)[winner.faction];
    uint factionID = _faction.byName(factionName);
    
    uint winnings = gladiatorWinnings(tournamentId);

    if (factionID > 0) {
      uint factionWinnings = winnings.mul(25).div(100);
      _assets.safeTransferFrom(address(this), address(_faction), _prestigeId, winnings, abi.encode(factionID));
      winnings = winnings.sub(factionWinnings);
    }

    // console.log('winnings', winnings);
    _claimedByGladiator[tournamentId] = true;
    _assets.safeTransferFrom(address(this), _gladiatorContract, _prestigeId, winnings, abi.encode(winner.gladiator));
    return true;
  }

  function onERC1155Received(
    address, // operator
    address from,
    uint256 id,
    uint256 value,
    bytes calldata data
  ) external override returns(bytes4) {
    require(msg.sender == address(_assets), "BettingPool#onERC1155Received: invalid asset address");
    require(id == _prestigeId, "BettingPool#Invalid token send");
    if (from == address(0)) {
      // this is a MINT so just accept it
      return IERC1155Receiver.onERC1155Received.selector;
    }
    (uint256 tournamentId, uint256 gladiatorId) = abi.decode(data, (uint256, uint256));
    // console.log("bet!", tournamentId, gladiatorId, from);
    require(!_tournaments.started(tournamentId), "BettingPool#Tournament already started");
    betsByUser[tournamentId][from][gladiatorId] += value;
    betsByGladiator[tournamentId][gladiatorId] += value;
    betsByTournament[tournamentId] += value;
    
    emit BetPlaced(from, tournamentId, gladiatorId);

    return IERC1155Receiver.onERC1155Received.selector;
  }

  function onERC1155BatchReceived(
    address,
    address,
    uint256[] memory,
    uint256[] memory,
    bytes calldata
  ) pure public override returns(bytes4) {
      revert("BettingPool#No batch allowed");
  }

  function _msgSender() internal view override(Context,EIP712MetaTransaction) returns (address payable) {
    return EIP712MetaTransaction.msgSender();
  }
}

File 55 of 59 : AssetsERC20Wrapper.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0;

import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC1155/ERC1155Receiver.sol";
import "./interfaces/IAssets.sol";
import "./interfaces/IAssetsERC20Wrapper.sol";

import "hardhat/console.sol";

contract AssetsERC20Wrapper is IAssetsERC20Wrapper, ERC20, ERC1155Receiver {
    using SafeMath for uint256;
    
    IAssets immutable _tokenHolder;
    uint256 private _tokenID; // the specific token id this erc20 is wrapping

    string private _name;
    string private _symbol;
    uint8 private _decimals = 18;
    mapping (address => mapping (address => uint256)) private _allowances;

    constructor(address holder) ERC20('', '') {
        _tokenHolder = IAssets(holder);
        _tokenID = 1; // initialize the contract for the copy
    }

    function init(uint256 tokenID, string calldata name_, string calldata symbol_) public {
        _tokenID = tokenID;
        _name = name_;
        _symbol = symbol_;
    }

    function unwrap(address account, address to, uint256 amount) override external {
        if (account != _msgSender()) {
            uint256 currentAllowance = allowance(account, _msgSender());
            require(currentAllowance >= amount, "AssetsERC20Wrapper: unwrap amount exceeds allowance");
            _approve(account, _msgSender(), currentAllowance.sub(amount));
        }
        _burn(account, amount);
        _tokenHolder.safeTransferFrom(address(this), to, _tokenID, amount, '');
    }

    function onERC1155Received(
        address, // operator
        address from,
        uint256 id,
        uint256 value,
        bytes calldata // data
    ) external override returns (bytes4) {
        require(
            msg.sender == address(_tokenHolder),
            "AssetsERC20Wrapper#onERC1155: invalid asset address"
        );
        require(id == _tokenID, "AssetsERC20Wrapper: invalid token id");

        _mint(from, value);

        return IERC1155Receiver.onERC1155Received.selector;
    }

    function onERC1155BatchReceived(
        address,
        address,
        uint256[] memory,
        uint256[] memory,
        bytes calldata
    ) public pure override returns (bytes4) {
        revert("batch send is not supported");
    }
    
}

File 56 of 59 : WrapperFactory.sol
pragma solidity ^0.7.4;

import "./AssetsERC20Wrapper.sol";
import "./CloneFactory.sol";

contract WrapperFactory is CloneFactory {

  address public libraryAddress;
  address public holderAddress;

  mapping(uint256 => address) public getWrapper; // mapping of tokenID to address

  event WrapperCreated(address proxyAddress);

  constructor(address _libraryAddress, address _holderAddress) {
    libraryAddress = _libraryAddress;
    holderAddress = _holderAddress;
  }

  function createWrapper(uint256 tokenID, string calldata name, string calldata symbol) public returns(address) {
    require(getWrapper[tokenID] == address(0), "wrapper already created");
    address clone = createClone(libraryAddress);
    AssetsERC20Wrapper(clone).init(tokenID, name, symbol);
    getWrapper[tokenID] = address(clone);
    emit WrapperCreated(clone);
    return clone;
  }
}

File 57 of 59 : CloneFactory.sol
pragma solidity >= 0.6.0;

// see https://github.com/optionality/clone-factory/blob/master/contracts/CloneFactory.sol


/*
The MIT License (MIT)
Copyright (c) 2018 Murray Software, LLC.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
//solhint-disable max-line-length
//solhint-disable no-inline-assembly

contract CloneFactory {

  function createClone(address target) internal returns (address result) {
    bytes20 targetBytes = bytes20(target);
    assembly {
      let clone := mload(0x40)
      mstore(clone, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
      mstore(add(clone, 0x14), targetBytes)
      mstore(add(clone, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
      result := create(0, clone, 0x37)
    }
  }

  function isClone(address target, address query) internal view returns (bool result) {
    bytes20 targetBytes = bytes20(target);
    assembly {
      let clone := mload(0x40)
      mstore(clone, 0x363d3d373d3d3d363d7300000000000000000000000000000000000000000000)
      mstore(add(clone, 0xa), targetBytes)
      mstore(add(clone, 0x1e), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)

      let other := add(clone, 0x40)
      extcodecopy(query, other, 0, 0x2d)
      result := and(
        eq(mload(clone), mload(other)),
        eq(mload(add(clone, 0xd)), mload(add(other, 0xd)))
      )
    }
  }
}

File 58 of 59 : BettingLogger.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.4;
pragma experimental ABIEncoderV2;
import "@openzeppelin/contracts/utils/EnumerableSet.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "hardhat/console.sol";

contract BettingLogger is Ownable {
    using EnumerableSet for EnumerableSet.AddressSet;
    
    EnumerableSet.AddressSet private allBettors;
    mapping(uint => EnumerableSet.AddressSet) private bettors; // tournamentID => bettors

    function add(uint tournamentId) public {
        bettors[tournamentId].add(msg.sender);
        allBettors.add(msg.sender);
    }

    function allFor(uint tournamentId) public view returns (address[] memory ids) {
        EnumerableSet.AddressSet storage addrs = bettors[tournamentId];
        uint len = addrs.length();
        ids = new address[](len);
        for (uint i; i < len; i++) {
            ids[i] = addrs.at(i);
        }
        return ids;
    }

    function lengthFor(uint tournamentId) public view returns (uint) {
        return bettors[tournamentId].length();
    }

    function sliceFor(uint tournamentId, uint start, uint length) public view returns (address[] memory ids) {
        EnumerableSet.AddressSet storage addrs = bettors[tournamentId];
        ids = new address[](length);
        for (uint i; i < length; i++) {
            ids[i] = addrs.at(i + start);
        }
        return ids;
    }

    // functions for all users

    function all() public view returns (address[] memory ids) {
        uint len = allBettors.length();
        ids = new address[](len);
        for (uint i; i < len; i++) {
            ids[i] = allBettors.at(i);
        }
        return ids;
    }

    function length() public view returns (uint) {
        return allBettors.length();
    }

    function slice(uint start, uint length) public view returns (address[] memory ids) {
        ids = new address[](length);
        for (uint i; i < length; i++) {
            ids[i] = allBettors.at(start + i);
        }
        return ids;
    }

    // restricted functions

    function removeFor(uint tournamentId, address addr) public onlyOwner {
        bettors[tournamentId].remove(addr);
    }

    function removeFromAll(address addr) public onlyOwner {
        allBettors.remove(addr);
    }

    function adminAdd(uint tournamentId, address addr) public onlyOwner {
        bettors[tournamentId].add(addr);
        allBettors.add(addr);
    }
    
}

File 59 of 59 : FreeBet.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.4;
pragma experimental ABIEncoderV2;
import "@openzeppelin/contracts/access/Ownable.sol";

contract FreeBet is Ownable {
    mapping(address => uint32) public maxFreeBets;
    mapping(address => uint32) public usedFreeBets;

    function inc(address userAddress) public onlyOwner returns (uint32) {
        return usedFreeBets[userAddress]++;
    }

    function setMaxFreeBets(address userAddress, uint32 max) public onlyOwner {
        maxFreeBets[userAddress] = max;
    }
}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 1
  },
  "evmVersion": "istanbul",
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "abi"
      ]
    }
  },
  "metadata": {
    "useLiteralContent": true
  }
}

Contract ABI

[{"inputs":[{"internalType":"address","name":"oldAssets","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"userAddress","type":"address"},{"indexed":false,"internalType":"address payable","name":"relayerAddress","type":"address"},{"indexed":false,"internalType":"bytes","name":"functionSignature","type":"bytes"}],"name":"MetaTransactionExecuted","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":true,"internalType":"address","name":"operator","type":"address"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256[]","name":"ids","type":"uint256[]"},{"indexed":false,"internalType":"uint256[]","name":"values","type":"uint256[]"}],"name":"TransferBatch","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"TransferSingle","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"value","type":"string"},{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"}],"name":"URI","type":"event"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"accountTokens","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"operator_","type":"address"},{"internalType":"bytes32","name":"name","type":"bytes32"}],"name":"addOperator","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"accounts","type":"address[]"},{"internalType":"uint256[]","name":"ids","type":"uint256[]"}],"name":"balanceOfBatch","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"bytes32","name":"name","type":"bytes32"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"burn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"name","type":"bytes32"}],"name":"currentSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"deprecatedAssets","outputs":[{"internalType":"contract IAssets","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"userAddress","type":"address"},{"internalType":"bytes","name":"functionSignature","type":"bytes"},{"internalType":"bytes32","name":"sigR","type":"bytes32"},{"internalType":"bytes32","name":"sigS","type":"bytes32"},{"internalType":"uint8","name":"sigV","type":"uint8"}],"name":"executeMetaTransaction","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"name","type":"bytes32"},{"internalType":"uint256","name":"id","type":"uint256"}],"name":"exists","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"forge","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"getNonce","outputs":[{"internalType":"uint256","name":"nonce","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"name","type":"bytes32"}],"name":"idRange","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"address","name":"operator","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"}],"name":"isApprovedOrOwner","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"}],"name":"isOwner","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"bytes32","name":"name","type":"bytes32"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"mint","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"nameForID","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"from","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC1155Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"name","type":"bytes32"},{"internalType":"bool","name":"isNFT","type":"bool"},{"internalType":"uint256","name":"totalSupply","type":"uint256"},{"internalType":"address[]","name":"operators","type":"address[]"}],"name":"register","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"contractAddress","type":"address"}],"name":"registerAssetContract","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator_","type":"address"},{"internalType":"bytes32","name":"name","type":"bytes32"}],"name":"removeOperator","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256[]","name":"ids","type":"uint256[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeBatchTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","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":"bytes32","name":"name","type":"bytes32"}],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"uri","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"}]

60a06040523480156200001157600080fd5b5060405162003fce38038062003fce8339810160408190526200003491620003bf565b6040518060400160405280600681526020016541737365747360d01b815250604051806040016040528060018152602001603160f81b81525081816040518060400160405280600f81526020016e1798989a9a97bdb4b23e973539b7b760891b815250620000af6301ffc9a760e01b620001f460201b60201c565b620000ba8162000279565b620000cc636cdb3d1360e11b620001f4565b620000de6303a24d0760e21b620001f4565b506000620000eb62000292565b600480546001600160a01b0319166001600160a01b038316908117909155604051919250906000907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908290a35060405180608001604052806052815260200162003f7c6052913980519060200120828051906020012082805190602001206200017a620002af60201b60201c565b3060405160200180868152602001858152602001848152602001838152602001826001600160a01b03168152602001955050505050506040516020818303038152906040528051906020012060058190555050505050806001600160a01b03166080816001600160a01b031660601b8152505050620003ef565b6001600160e01b0319808216141562000254576040805162461bcd60e51b815260206004820152601c60248201527f4552433136353a20696e76616c696420696e7465726661636520696400000000604482015290519081900360640190fd5b6001600160e01b0319166000908152602081905260409020805460ff19166001179055565b80516200028e90600390602084019062000313565b5050565b6000620002a9620002b460201b62001f8b1760201c565b90505b90565b600190565b6000333014156200030e5760606000368080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152505050503601516001600160a01b03169150620002ac9050565b503390565b828054600181600116156101000203166002900490600052602060002090601f0160209004810192826200034b576000855562000396565b82601f106200036657805160ff191683800117855562000396565b8280016001018555821562000396579182015b828111156200039657825182559160200191906001019062000379565b50620003a4929150620003a8565b5090565b5b80821115620003a45760008155600101620003a9565b600060208284031215620003d1578081fd5b81516001600160a01b0381168114620003e8578182fd5b9392505050565b60805160601c613b6562000417600039806116f75280611b495280611b8b5250613b656000f3fe60806040526004361061015c5760003560e01c8062fdd58e1461016157806301ffc9a714610197578063031e3f99146101c4578063080df79b146101e45780630c53c51c146102065780630e89341c146102265780632d0335ab146102465780632eb2c2d6146102665780634460fb6d146102865780634af74fb0146102a65780634e1273f4146102d45780635cb316351461030157806364c6907014610321578063715018a61461034157806372982cd2146103565780638da5cb5b14610376578063a19d146014610398578063a22cb465146103b8578063b524abcf146103d8578063ba59cfbd146103f8578063c37a044c14610418578063c8383b4114610438578063cfca080a14610458578063de26648a1461046d578063e327a6af1461048d578063e774e30c146104ad578063e985e9c5146104cd578063f23a6e61146104ed578063f242432a1461051a578063f2fde38b1461053a575b600080fd5b34801561016d57600080fd5b5061018161017c366004612fe7565b61055a565b60405161018e91906133d2565b60405180910390f35b3480156101a357600080fd5b506101b76101b23660046132d9565b6105cc565b60405161018e91906133c7565b3480156101d057600080fd5b506101b76101df366004612fe7565b6105ef565b3480156101f057600080fd5b506102046101ff366004612d73565b610678565b005b6102196102143660046130a6565b6108a4565b60405161018e91906133f0565b34801561023257600080fd5b50610219610241366004613234565b610c0d565b34801561025257600080fd5b50610181610261366004612d73565b610ca5565b34801561027257600080fd5b50610204610281366004612dc7565b610cc0565b34801561029257600080fd5b506102046102a1366004613012565b610fb9565b3480156102b257600080fd5b506102c66102c1366004613234565b611039565b60405161018e929190613684565b3480156102e057600080fd5b506102f46102ef3660046131b8565b61107e565b60405161018e9190613383565b34801561030d57600080fd5b506101b761031c3660046132b8565b6111fb565b34801561032d57600080fd5b506101b761033c366004612fe7565b611256565b34801561034d57600080fd5b506102046112db565b34801561036257600080fd5b506101b7610371366004612e70565b61136b565b34801561038257600080fd5b5061038b6113a3565b60405161018e919061336f565b3480156103a457600080fd5b506102f46103b3366004612d73565b6113b3565b3480156103c457600080fd5b506102046103d3366004612fba565b61146b565b3480156103e457600080fd5b506101816103f3366004613234565b61155a565b34801561040457600080fd5b50610181610413366004613234565b61156f565b34801561042457600080fd5b50610181610433366004613234565b611664565b34801561044457600080fd5b506101b7610453366004613046565b611679565b34801561046457600080fd5b5061038b6116f5565b34801561047957600080fd5b506102f4610488366004613046565b611719565b34801561049957600080fd5b506101b76104a8366004612fe7565b6118a3565b3480156104b957600080fd5b506102046104c8366004613264565b6118b8565b3480156104d957600080fd5b506101b76104e8366004612d8f565b611b0e565b3480156104f957600080fd5b5061050d610508366004612eb0565b611b3c565b60405161018e91906133db565b34801561052657600080fd5b50610204610535366004612f54565b611ceb565b34801561054657600080fd5b50610204610555366004612d73565b611ea4565b60006001600160a01b0383166105a15760405162461bcd60e51b815260040180806020018281038252602b815260200180613841602b913960400191505060405180910390fd5b5060008181526001602090815260408083206001600160a01b03861684529091529020545b92915050565b6001600160e01b0319811660009081526020819052604090205460ff165b919050565b6000818152600960205260408120600481018261060a611f8b565b6001600160a01b0316815260208101919091526040016000205460ff1661064c5760405162461bcd60e51b815260040161064390613482565b60405180910390fd5b6001600160a01b0384166000908152600490910160205260409020805460ff1916905550600192915050565b610680611fe8565b6004546001600160a01b039081169116146106d0576040805162461bcd60e51b81526020600482018190526024820152600080516020613a34833981519152604482015290519081900360640190fd5b60008190506108a0816001600160a01b031663c9230c5d6040518163ffffffff1660e01b815260040160206040518083038186803b15801561071157600080fd5b505afa158015610725573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610749919061324c565b826001600160a01b031663177c89eb6040518163ffffffff1660e01b815260040160206040518083038186803b15801561078257600080fd5b505afa158015610796573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107ba9190613218565b836001600160a01b0316638f12c2f46040518163ffffffff1660e01b815260040160206040518083038186803b1580156107f357600080fd5b505afa158015610807573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061082b919061324c565b846001600160a01b0316632b42e5556040518163ffffffff1660e01b815260040160006040518083038186803b15801561086457600080fd5b505afa158015610878573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526104c89190810190613120565b5050565b606060006108b186611ff7565b90506000356001600160e01b031990811690821614156109025760405162461bcd60e51b815260040180806020018281038252603d81526020018061392a603d913960400191505060405180910390fd5b61090a612c0e565b50604080516060810182526001600160a01b038916600081815260066020908152908490205483528201529081018790526109488882888888612013565b6109835760405162461bcd60e51b8152600401808060200182810382526021815260200180613a746021913960400191505060405180910390fd5b6001600160a01b0388166000908152600660205260409020546109a79060016120fd565b600660008a6001600160a01b03166001600160a01b031681526020019081526020016000208190555060006060306001600160a01b0316898b6040516020018083805190602001908083835b60208310610a125780518252601f1990920191602091820191016109f3565b6001836020036101000a038019825116818451168082178552505050505050905001826001600160a01b031660601b8152601401925050506040516020818303038152906040526040518082805190602001908083835b60208310610a885780518252601f199092019160209182019101610a69565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114610aea576040519150601f19603f3d011682016040523d82523d6000602084013e610aef565b606091505b509150915081610b45576040805162461bcd60e51b815260206004820152601c60248201527b119d5b98dd1a5bdb8818d85b1b081b9bdd081cdd58d8d95cdcd99d5b60221b604482015290519081900360640190fd5b7f5845892132946850460bff5a0083f71031bc5bf9aadcd40f1de79423eac9b10b8a338b60405180846001600160a01b03168152602001836001600160a01b0316815260200180602001828103825283818151815260200191508051906020019080838360005b83811015610bc4578181015183820152602001610bac565b50505050905090810190601f168015610bf15780820380516001836020036101000a031916815260200191505b5094505050505060405180910390a19998505050505050505050565b60038054604080516020601f6002600019610100600188161502019095169490940493840181900481028201810190925282815260609390929091830182828015610c995780601f10610c6e57610100808354040283529160200191610c99565b820191906000526020600020905b815481529060010190602001808311610c7c57829003601f168201915b50505050509050919050565b6001600160a01b031660009081526006602052604090205490565b8151835114610d005760405162461bcd60e51b8152600401808060200182810382526028815260200180613ae76028913960400191505060405180910390fd5b6001600160a01b038416610d455760405162461bcd60e51b81526004018080602001828103825260258152602001806139906025913960400191505060405180910390fd5b610d4d611fe8565b6001600160a01b0316856001600160a01b03161480610d735750610d73856104e8611fe8565b610dae5760405162461bcd60e51b81526004018080602001828103825260328152602001806139b56032913960400191505060405180910390fd5b6000610db8611fe8565b9050610dc881878787878761215c565b60005b8451811015610ec9576000858281518110610de257fe5b602002602001015190506000858381518110610dfa57fe5b60200260200101519050610e67816040518060600160405280602a8152602001613a0a602a91396001600086815260200190815260200160002060008d6001600160a01b03166001600160a01b031681526020019081526020016000205461226f9092919063ffffffff16565b60008381526001602090815260408083206001600160a01b038e811685529252808320939093558a1681522054610e9e90826120fd565b60009283526001602081815260408086206001600160a01b038d168752909152909320555001610dcb565b50846001600160a01b0316866001600160a01b0316826001600160a01b03167f4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb8787604051808060200180602001838103835285818151815260200191508051906020019060200280838360005b83811015610f4f578181015183820152602001610f37565b50505050905001838103825284818151815260200191508051906020019060200280838360005b83811015610f8e578181015183820152602001610f76565b5050505090500194505050505060405180910390a4610fb1818787878787612306565b505050505050565b6000828152600960205260409020805460ff1615610fe95760405162461bcd60e51b815260040161064390613543565b610fff84610ff5611f8b565b836001015461136b565b61101b5760405162461bcd60e51b81526004016106439061343a565b61102a8482600101548461257c565b60030180549190910390555050565b6000818152600960205260408120805482919060ff161561106f5760018101546002909101549092508201600019019050611079565b6001015491508190505b915091565b606081518351146110c05760405162461bcd60e51b8152600401808060200182810382526029815260200180613abe6029913960400191505060405180910390fd5b606083516001600160401b03811180156110d957600080fd5b50604051908082528060200260200182016040528015611103578160200160208202803683370190505b50905060005b84518110156111f35760006001600160a01b031685828151811061112957fe5b60200260200101516001600160a01b031614156111775760405162461bcd60e51b815260040180806020018281038252603181526020018061386c6031913960400191505060405180910390fd5b6001600085838151811061118757fe5b6020026020010151815260200190815260200160002060008683815181106111ab57fe5b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020548282815181106111e057fe5b6020908102919091010152600101611109565b509392505050565b6000828152600960205260408120805460ff1661123157828160010154148015611229575060008160030154115b9150506105c6565b8281600101541115801561124e5750806003015481600101540183105b949350505050565b60008181526009602052604081206004810182611271611f8b565b6001600160a01b0316815260208101919091526040016000205460ff166112aa5760405162461bcd60e51b815260040161064390613482565b6001600160a01b0384166000908152600490910160205260409020805460ff19166001908117909155905092915050565b6112e3611fe8565b6004546001600160a01b03908116911614611333576040805162461bcd60e51b81526020600482018190526024820152600080516020613a34833981519152604482015290519081900360640190fd5b6004546040516000916001600160a01b031690600080516020613a54833981519152908390a3600480546001600160a01b0319169055565b60006113778484611b0e565b8061124e5750826001600160a01b0316846001600160a01b031614801561124e575061124e84836118a3565b6004546001600160a01b03165b90565b6001600160a01b0381166000908152600a60205260408120606091906113d89061269d565b90506060816001600160401b03811180156113f257600080fd5b5060405190808252806020026020018201604052801561141c578160200160208202803683370190505b50905060005b828110156111f3576001600160a01b0385166000908152600a6020526040902061144c90826126a8565b82828151811061145857fe5b6020908102919091010152600101611422565b816001600160a01b031661147d611fe8565b6001600160a01b031614156114c35760405162461bcd60e51b8152600401808060200182810382526029815260200180613a956029913960400191505060405180910390fd5b80600260006114d0611fe8565b6001600160a01b03908116825260208083019390935260409182016000908120918716808252919093529120805460ff191692151592909217909155611514611fe8565b6001600160a01b03167f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c318360405180821515815260200191505060405180910390a35050565b60009081526009602052604090206002015490565b60085460009060001901815b81811161165d57818114156115ef576000600960006007848154811061159d57fe5b9060005260206000200154815260200190815260200160002090506115c1816126b4565b85116115e957600782815481106115d457fe5b906000526020600020015493505050506105ea565b50611655565b83600882815481106115fd57fe5b90600052602060002001541115801561162f57506008816001018154811061162157fe5b906000526020600020015484105b15611655576007818154811061164157fe5b9060005260206000200154925050506105ea565b60010161157b565b5050919050565b60009081526009602052604090206003015490565b6000806116858561156f565b600081815260096020526040812091925060048201906116a3611f8b565b6001600160a01b0316815260208101919091526040016000205460ff166116dc5760405162461bcd60e51b81526004016106439061364d565b6116e8878787876126e0565b5060019695505050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b60008381526009602052604081206060916004820190611737611f8b565b6001600160a01b0316815260208101919091526040016000205460ff166117705760405162461bcd60e51b815260040161064390613403565b806002015484826003015401111561179a5760405162461bcd60e51b8152600401610643906134b9565b805460609060ff161561184057846001600160401b03811180156117bd57600080fd5b506040519080825280602002602001820160405280156117e7578160200160208202803683370190505b50905060005b8581101561183a5761180e88828560030154866001015401016001886126e0565b8083600301548460010154010182828151811061182757fe5b60209081029190910101526001016117ed565b5061188e565b604080516001808252818301909252906020808301908036833701905050905081600101548160008151811061187257fe5b60200260200101818152505061188e87836001015487876126e0565b60039091018054850190559050949350505050565b6000806118b0848461055a565b119392505050565b6118c0611fe8565b6004546001600160a01b03908116911614611910576040805162461bcd60e51b81526020600482018190526024820152600080516020613a34833981519152604482015290519081900360640190fd5b600082116119305760405162461bcd60e51b81526004016106439061356d565b600754600090611942575060006119b1565b600085815260096020526040902060020154156119715760405162461bcd60e51b8152600401610643906135b0565b6119ab6009600060076001600780549050038154811061198d57fe5b906000526020600020015481526020019081526020016000206126b4565b60010190505b6000858152600960205260408120805460ff1916861515178155600181018390556002810185905560038101829055905b8351811015611a395760018260040160008684815181106119ff57fe5b6020908102919091018101516001600160a01b03168252810191909152604001600020805460ff19169115159190911790556001016119e2565b508251611a79576001816004016000611a50611f8b565b6001600160a01b031681526020810191909152604001600020805460ff19169115159190911790555b600019611a85826126b4565b10611aa25760405162461bcd60e51b815260040161064390613629565b506007805460018181019092557fa66cc928b5edb82af9bd49922954155ab7b0942694bea4ce44661d9a8736c68801959095556008805495860181556000527ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee390940193909355505050565b6001600160a01b03918216600090815260026020908152604080832093909416825291909152205460ff1690565b6000336001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614611b865760405162461bcd60e51b8152600401610643906134f0565b6000807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316634af74fb067707265737469676560c01b6040518263ffffffff1660e01b8152600401611be091906133d2565b604080518083038186803b158015611bf757600080fd5b505afa158015611c0b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c2f9190613301565b91509150818710158015611c435750808711155b611c5f5760405162461bcd60e51b8152600401610643906135e2565b67707265737469676560c01b6000908152600960209081527f5a2317b07a17dafd10f0f9db1fe0fba2ada4dea0eb0f1d1cf63fbb9d94a6be4b546040805192830190529181527f5a2317b07a17dafd10f0f9db1fe0fba2ada4dea0eb0f1d1cf63fbb9d94a6be4a91611cd5918b91908a906126e0565b5063f23a6e6160e01b9998505050505050505050565b6001600160a01b038416611d305760405162461bcd60e51b81526004018080602001828103825260258152602001806139906025913960400191505060405180910390fd5b611d38611fe8565b6001600160a01b0316856001600160a01b03161480611d5e5750611d5e856104e8611fe8565b611d995760405162461bcd60e51b81526004018080602001828103825260298152602001806139676029913960400191505060405180910390fd5b6000611da3611fe8565b9050611dc3818787611db4886127d6565b611dbd886127d6565b8761215c565b611e0a836040518060600160405280602a8152602001613a0a602a913960008781526001602090815260408083206001600160a01b038d168452909152902054919061226f565b60008581526001602090815260408083206001600160a01b038b81168552925280832093909355871681522054611e4190846120fd565b60008581526001602090815260408083206001600160a01b03808b168086529184529382902094909455805188815291820187905280518a84169386169260008051602061382183398151915292908290030190a4610fb181878787878761281a565b611eac611fe8565b6004546001600160a01b03908116911614611efc576040805162461bcd60e51b81526020600482018190526024820152600080516020613a34833981519152604482015290519081900360640190fd5b6001600160a01b038116611f415760405162461bcd60e51b81526004018080602001828103825260268152602001806138e06026913960400191505060405180910390fd5b6004546040516001600160a01b03808416921690600080516020613a5483398151915290600090a3600480546001600160a01b0319166001600160a01b0392909216919091179055565b600033301415611fe35760606000368080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152505050503601516001600160a01b031691506113b09050565b503390565b6000611ff2611f8b565b905090565b600081516000141561200b575060006105ea565b506020015190565b60008060016120296120248861298b565b612a0e565b84878760405160008152602001604052604051808581526020018460ff1681526020018381526020018281526020019450505050506020604051602081039080840390855afa158015612080573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b0381166120dc576040805162461bcd60e51b8152602060048201526011602482015270496e76616c6964207369676e617475726560781b604482015290519081900360640190fd5b866001600160a01b0316816001600160a01b03161491505095945050505050565b600082820183811015612155576040805162461bcd60e51b815260206004820152601b60248201527a536166654d6174683a206164646974696f6e206f766572666c6f7760281b604482015290519081900360640190fd5b9392505050565b60005b8351811015612266576001600160a01b038616158015906121b25750600083828151811061218957fe5b60200260200101516121ae888785815181106121a157fe5b602002602001015161055a565b0311155b15612203576122018482815181106121c657fe5b6020026020010151600a6000896001600160a01b03166001600160a01b03168152602001908152602001600020612a5a90919063ffffffff16565b505b6001600160a01b0385161561225e5761225c84828151811061222157fe5b6020026020010151600a6000886001600160a01b03166001600160a01b03168152602001908152602001600020612a6690919063ffffffff16565b505b60010161215f565b50505050505050565b600081848411156122fe5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b838110156122c35781810151838201526020016122ab565b50505050905090810190601f1680156122f05780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b612318846001600160a01b0316612a72565b15610fb157836001600160a01b031663bc197c8187878686866040518663ffffffff1660e01b815260040180866001600160a01b03168152602001856001600160a01b03168152602001806020018060200180602001848103845287818151815260200191508051906020019060200280838360005b838110156123a657818101518382015260200161238e565b50505050905001848103835286818151815260200191508051906020019060200280838360005b838110156123e55781810151838201526020016123cd565b50505050905001848103825285818151815260200191508051906020019080838360005b83811015612421578181015183820152602001612409565b50505050905090810190601f16801561244e5780820380516001836020036101000a031916815260200191505b5098505050505050505050602060405180830381600087803b15801561247357600080fd5b505af192505050801561249857506040513d602081101561249357600080fd5b505160015b61252d576124a46136d8565b806124af57506124f6565b60405162461bcd60e51b81526020600482018181528351602484015283518493919283926044019190850190808383600083156122c35781810151838201526020016122ab565b60405162461bcd60e51b81526004018080602001828103825260348152602001806137a36034913960400191505060405180910390fd5b6001600160e01b0319811663bc197c8160e01b146122665760405162461bcd60e51b81526004018080602001828103825260288152602001806137f96028913960400191505060405180910390fd5b6001600160a01b0383166125c15760405162461bcd60e51b81526004018080602001828103825260238152602001806139e76023913960400191505060405180910390fd5b60006125cb611fe8565b90506125fb818560006125dd876127d6565b6125e6876127d6565b6040518060200160405280600081525061215c565b612642826040518060600160405280602481526020016139066024913960008681526001602090815260408083206001600160a01b038b168452909152902054919061226f565b60008481526001602090815260408083206001600160a01b03808a168086529184528285209590955581518881529283018790528151939490939086169260008051602061382183398151915292908290030190a450505050565b60006105c682612a78565b60006121558383612a7c565b805460009060ff166126cb575060018101546105ea565b60018260020154836001015401039050919050565b6001600160a01b0384166127255760405162461bcd60e51b8152600401808060200182810382526021815260200180613b0f6021913960400191505060405180910390fd5b600061272f611fe8565b905061274181600087611db4886127d6565b60008481526001602090815260408083206001600160a01b038916845290915290205461276e90846120fd565b60008581526001602090815260408083206001600160a01b03808b168086529184528285209590955581518981529283018890528151909486169260008051602061382183398151915292908290030190a46127cf8160008787878761281a565b5050505050565b60408051600180825281830190925260609182919060208083019080368337019050509050828160008151811061280957fe5b602090810291909101015292915050565b61282c846001600160a01b0316612a72565b15610fb157836001600160a01b031663f23a6e6187878686866040518663ffffffff1660e01b815260040180866001600160a01b03168152602001856001600160a01b0316815260200184815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b838110156128bb5781810151838201526020016128a3565b50505050905090810190601f1680156128e85780820380516001836020036101000a031916815260200191505b509650505050505050602060405180830381600087803b15801561290b57600080fd5b505af192505050801561293057506040513d602081101561292b57600080fd5b505160015b61293c576124a46136d8565b6001600160e01b0319811663f23a6e6160e01b146122665760405162461bcd60e51b81526004018080602001828103825260288152602001806137f96028913960400191505060405180910390fd5b600060405180608001604052806043815260200161389d60439139805190602001208260000151836020015184604001518051906020012060405160200180858152602001848152602001836001600160a01b03168152602001828152602001945050505050604051602081830303815290604052805190602001209050919050565b6000612a18612ae0565b82604051602001808061190160f01b81525060020183815260200182815260200192505050604051602081830303815290604052805190602001209050919050565b60006121558383612ae6565b60006121558383612bac565b3b151590565b5490565b81546000908210612abe5760405162461bcd60e51b81526004018080602001828103825260228152602001806137d76022913960400191505060405180910390fd5b826000018281548110612acd57fe5b9060005260206000200154905092915050565b60055490565b60008181526001830160205260408120548015612ba25783546000198083019190810190600090879083908110612b1957fe5b9060005260206000200154905080876000018481548110612b3657fe5b600091825260208083209091019290925582815260018981019092526040902090840190558654879080612b6657fe5b600190038181906000526020600020016000905590558660010160008781526020019081526020016000206000905560019450505050506105c6565b60009150506105c6565b6000612bb88383612bf6565b612bee575081546001818101845560008481526020808220909301849055845484825282860190935260409020919091556105c6565b5060006105c6565b60009081526001919091016020526040902054151590565b60405180606001604052806000815260200160006001600160a01b03168152602001606081525090565b600082601f830112612c48578081fd5b8135612c5b612c56826136b5565b613692565b818152915060208083019084810181840286018201871015612c7c57600080fd5b60005b84811015612ca4578135612c928161377c565b84529282019290820190600101612c7f565b505050505092915050565b600082601f830112612cbf578081fd5b8135612ccd612c56826136b5565b818152915060208083019084810181840286018201871015612cee57600080fd5b60005b84811015612ca457813584529282019290820190600101612cf1565b600082601f830112612d1d578081fd5b81356001600160401b03811115612d3057fe5b612d43601f8201601f1916602001613692565b9150808252836020828501011115612d5a57600080fd5b8060208401602084013760009082016020015292915050565b600060208284031215612d84578081fd5b81356121558161377c565b60008060408385031215612da1578081fd5b8235612dac8161377c565b91506020830135612dbc8161377c565b809150509250929050565b600080600080600060a08688031215612dde578081fd5b8535612de98161377c565b94506020860135612df98161377c565b935060408601356001600160401b0380821115612e14578283fd5b612e2089838a01612caf565b94506060880135915080821115612e35578283fd5b612e4189838a01612caf565b93506080880135915080821115612e56578283fd5b50612e6388828901612d0d565b9150509295509295909350565b600080600060608486031215612e84578283fd5b8335612e8f8161377c565b92506020840135612e9f8161377c565b929592945050506040919091013590565b60008060008060008060a08789031215612ec8578081fd5b8635612ed38161377c565b95506020870135612ee38161377c565b9450604087013593506060870135925060808701356001600160401b0380821115612f0c578283fd5b818901915089601f830112612f1f578283fd5b813581811115612f2d578384fd5b8a6020828501011115612f3e578384fd5b6020830194508093505050509295509295509295565b600080600080600060a08688031215612f6b578081fd5b8535612f768161377c565b94506020860135612f868161377c565b9350604086013592506060860135915060808601356001600160401b03811115612fae578182fd5b612e6388828901612d0d565b60008060408385031215612fcc578182fd5b8235612fd78161377c565b91506020830135612dbc81613794565b60008060408385031215612ff9578182fd5b82356130048161377c565b946020939093013593505050565b600080600060608486031215613026578081fd5b83356130318161377c565b95602085013595506040909401359392505050565b6000806000806080858703121561305b578182fd5b84356130668161377c565b9350602085013592506040850135915060608501356001600160401b0381111561308e578182fd5b61309a87828801612d0d565b91505092959194509250565b600080600080600060a086880312156130bd578283fd5b85356130c88161377c565b945060208601356001600160401b038111156130e2578384fd5b6130ee88828901612d0d565b9450506040860135925060608601359150608086013560ff81168114613112578182fd5b809150509295509295909350565b60006020808385031215613132578182fd5b82516001600160401b03811115613147578283fd5b8301601f81018513613157578283fd5b8051613165612c56826136b5565b8181528381019083850185840285018601891015613181578687fd5b8694505b838510156131ac5780516131988161377c565b835260019490940193918501918501613185565b50979650505050505050565b600080604083850312156131ca578182fd5b82356001600160401b03808211156131e0578384fd5b6131ec86838701612c38565b93506020850135915080821115613201578283fd5b5061320e85828601612caf565b9150509250929050565b600060208284031215613229578081fd5b815161215581613794565b600060208284031215613245578081fd5b5035919050565b60006020828403121561325d578081fd5b5051919050565b60008060008060808587031215613279578182fd5b84359350602085013561328b81613794565b92506040850135915060608501356001600160401b038111156132ac578182fd5b61309a87828801612c38565b600080604083850312156132ca578182fd5b50508035926020909101359150565b6000602082840312156132ea578081fd5b81356001600160e01b031981168114612155578182fd5b60008060408385031215613313578182fd5b505080516020909101519092909150565b60008151808452815b818110156133495760208185018101518683018201520161332d565b8181111561335a5782602083870101525b50601f01601f19169290920160200192915050565b6001600160a01b0391909116815260200190565b6020808252825182820181905260009190848201906040850190845b818110156133bb5783518352928401929184019160010161339f565b50909695505050505050565b901515815260200190565b90815260200190565b6001600160e01b031991909116815260200190565b6000602082526121556020830184613324565b6020808252601e908201527f4173736574733a204e6f7420617574686f72697a656420746f206d696e740000604082015260600190565b60208082526028908201527f4173736574733a2063616c6c6572206973206e6f74206f776e6572206e6f7220604082015267185c1c1c9bdd995960c21b606082015260800190565b6020808252601d908201527f4173736574733a204e6f7420617574686f72697a656420746f20616464000000604082015260600190565b6020808252601e908201527f4173736574733a20546f6b656e20737570706c79206578686175737465640000604082015260600190565b60208082526033908201527f417373657473236f6e4552433131353552656365697665643a20696e76616c6960408201527264206f6c64206173736574206164647265737360681b606082015260800190565b60208082526010908201526f63616e6e6f74206275726e204e46547360801b604082015260600190565b60208082526023908201527f746f74616c20737570706c79206d75737420626520677265617465722074686160408201526206e20360ec1b606082015260800190565b60208082526018908201527730b9b9b2ba103730b6b29030b63932b0b23c903a30b5b2b760411b604082015260600190565b60208082526027908201527f417373657473234f6e6c7920737570706f727473207072657374696765206d6960408201526633b930ba34b7b760c91b606082015260800190565b6020808252600a90820152696f7574206f662069647360b01b604082015260600190565b6020808252601f908201527f4173736574733a204e6f7420617574686f72697a656420746f20666f72676500604082015260600190565b918252602082015260400190565b6040518181016001600160401b03811182821017156136ad57fe5b604052919050565b60006001600160401b038211156136c857fe5b5060209081020190565b60e01c90565b600060443d10156136e8576113b0565b600481823e6308c379a06136fc82516136d2565b14613706576113b0565b6040513d600319016004823e80513d6001600160401b03808311602484018310171561373557505050506113b0565b8284019250825191508082111561374f57505050506113b0565b503d83016020828401011115613767575050506113b0565b601f01601f1916810160200160405291505090565b6001600160a01b038116811461379157600080fd5b50565b801515811461379157600080fdfe455243313135353a207472616e7366657220746f206e6f6e2045524331313535526563656976657220696d706c656d656e746572456e756d657261626c655365743a20696e646578206f7574206f6620626f756e6473455243313135353a204552433131353552656365697665722072656a656374656420746f6b656e73c3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62455243313135353a2062616c616e636520717565727920666f7220746865207a65726f2061646472657373455243313135353a2062617463682062616c616e636520717565727920666f7220746865207a65726f20616464726573734d6574615472616e73616374696f6e2875696e74323536206e6f6e63652c616464726573732066726f6d2c62797465732066756e6374696f6e5369676e6174757265294f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373455243313135353a206275726e20616d6f756e7420657863656564732062616c616e636566756e6374696f6e5369676e61747572652063616e206e6f74206265206f6620657865637574654d6574615472616e73616374696f6e206d6574686f64455243313135353a2063616c6c6572206973206e6f74206f776e6572206e6f7220617070726f766564455243313135353a207472616e7366657220746f20746865207a65726f2061646472657373455243313135353a207472616e736665722063616c6c6572206973206e6f74206f776e6572206e6f7220617070726f766564455243313135353a206275726e2066726f6d20746865207a65726f2061646472657373455243313135353a20696e73756666696369656e742062616c616e636520666f72207472616e736665724f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65728be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e05369676e657220616e64207369676e617475726520646f206e6f74206d61746368455243313135353a2073657474696e6720617070726f76616c2073746174757320666f722073656c66455243313135353a206163636f756e747320616e6420696473206c656e677468206d69736d61746368455243313135353a2069647320616e6420616d6f756e7473206c656e677468206d69736d61746368455243313135353a206d696e7420746f20746865207a65726f2061646472657373a2646970667358221220ac4eb779b9d436be910c5937b8784cd29fe4799ad9e710cfd39f6d27399c7a8164736f6c63430007040033454950373132446f6d61696e28737472696e67206e616d652c737472696e672076657273696f6e2c75696e7432353620636861696e49642c6164647265737320766572696679696e67436f6e7472616374290000000000000000000000000000000000000000000000000000000000000000

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

0000000000000000000000000000000000000000000000000000000000000000

-----Decoded View---------------
Arg [0] : oldAssets (address): 0x0000000000000000000000000000000000000000

-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 0000000000000000000000000000000000000000000000000000000000000000


Deployed ByteCode Sourcemap

497:8155:22:-:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2966:220:7;;;;;;;;;;-1:-1:-1;2966:220:7;;;;;:::i;:::-;;:::i;:::-;;;;;;;:::i;:::-;;;;;;;;965:140:3;;;;;;;;;;-1:-1:-1;965:140:3;;;;;:::i;:::-;;:::i;:::-;;;;;;;:::i;2902:263:22:-;;;;;;;;;;-1:-1:-1;2902:263:22;;;;;:::i;:::-;;:::i;2347:287::-;;;;;;;;;;-1:-1:-1;2347:287:22;;;;;:::i;:::-;;:::i;:::-;;1404:1088:57;;;;;;:::i;:::-;;:::i;:::-;;;;;;;:::i;2727:97:7:-;;;;;;;;;;-1:-1:-1;2727:97:7;;;;;:::i;:::-;;:::i;2790:106:57:-;;;;;;;;;;-1:-1:-1;2790:106:57;;;;;:::i;:::-;;:::i;5593:1184:7:-;;;;;;;;;;-1:-1:-1;5593:1184:7;;;;;:::i;:::-;;:::i;4665:426:22:-;;;;;;;;;;-1:-1:-1;4665:426:22;;;;;:::i;:::-;;:::i;5987:270::-;;;;;;;;;;-1:-1:-1;5987:270:22;;;;;:::i;:::-;;:::i;:::-;;;;;;;;:::i;3343:615:7:-;;;;;;;;;;-1:-1:-1;3343:615:7;;;;;:::i;:::-;;:::i;:::-;;;;;;;:::i;6300:303:22:-;;;;;;;;;;-1:-1:-1;6300:303:22;;;;;:::i;:::-;;:::i;2638:260::-;;;;;;;;;;-1:-1:-1;2638:260:22;;;;;:::i;:::-;;:::i;1706:145:2:-;;;;;;;;;;;;;:::i;5237:230:22:-;;;;;;;;;;-1:-1:-1;5237:230:22;;;;;:::i;:::-;;:::i;1083:77:2:-;;;;;;;;;;;;;:::i;:::-;;;;;;;:::i;6873:330:22:-;;;;;;;;;;-1:-1:-1;6873:330:22;;;;;:::i;:::-;;:::i;4026:306:7:-;;;;;;;;;;-1:-1:-1;4026:306:7;;;;;:::i;:::-;;:::i;6607:127:22:-;;;;;;;;;;-1:-1:-1;6607:127:22;;;;;:::i;:::-;;:::i;5532:451::-;;;;;;;;;;-1:-1:-1;5532:451:22;;;;;:::i;:::-;;:::i;6738:131::-;;;;;;;;;;-1:-1:-1;6738:131:22;;;;;:::i;:::-;;:::i;4316:343::-;;;;;;;;;;-1:-1:-1;4316:343:22;;;;;:::i;:::-;;:::i;687:41::-;;;;;;;;;;;;;:::i;3169:866::-;;;;;;;;;;-1:-1:-1;3169:866:22;;;;;:::i;:::-;;:::i;5095:138::-;;;;;;;;;;-1:-1:-1;5095:138:22;;;;;:::i;:::-;;:::i;1392:951::-;;;;;;;;;;-1:-1:-1;1392:951:22;;;;;:::i;:::-;;:::i;4399:158:7:-;;;;;;;;;;-1:-1:-1;4399:158:7;;;;;:::i;:::-;;:::i;8010:640:22:-;;;;;;;;;;-1:-1:-1;8010:640:22;;;;;:::i;:::-;;:::i;:::-;;;;;;;:::i;4624:897:7:-;;;;;;;;;;-1:-1:-1;4624:897:7;;;;;:::i;:::-;;:::i;2000:240:2:-;;;;;;;;;;-1:-1:-1;2000:240:2;;;;;:::i;:::-;;:::i;2966:220:7:-;3044:7;-1:-1:-1;;;;;3071:21:7;;3063:77;;;;-1:-1:-1;;;3063:77:7;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;3157:13:7;;;;:9;:13;;;;;;;;-1:-1:-1;;;;;3157:22:7;;;;;;;;;;2966:220;;;;;:::o;965:140:3:-;-1:-1:-1;;;;;;1065:33:3;;1042:4;1065:33;;;;;;;;;;;;;965:140;;;;:::o;2902:263:22:-;2977:4;3015:13;;;:7;:13;;;;;3042:15;;;2977:4;3058:11;:9;:11::i;:::-;-1:-1:-1;;;;;3042:28:22;;;;;;;;;;;;-1:-1:-1;3042:28:22;;;;3034:70;;;;-1:-1:-1;;;3034:70:22;;;;;;;:::i;:::-;;;;;;;;;-1:-1:-1;;;;;3117:26:22;;;;;;:15;;;;:26;;;;;3110:33;;-1:-1:-1;;3110:33:22;;;-1:-1:-1;3110:33:22;2902:263;;;;:::o;2347:287::-;1297:12:2;:10;:12::i;:::-;1287:6;;-1:-1:-1;;;;;1287:6:2;;;:22;;;1279:67;;;;;-1:-1:-1;;;1279:67:2;;;;;;;;;;;;;-1:-1:-1;;;;;;;;;;;1279:67:2;;;;;;;;;;;;;;;2434:24:22::1;2480:15;2434:62;;2502:127;2518:5;-1:-1:-1::0;;;;;2518:15:22::1;;:17;;;;;;;;;;;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;2543:5;-1:-1:-1::0;;;;;2543:16:22::1;;:18;;;;;;;;;;;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;2569:5;-1:-1:-1::0;;;;;2569:22:22::1;;:24;;;;;;;;;;;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;2601:5;-1:-1:-1::0;;;;;2601:20:22::1;;:22;;;;;;;;;;;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;::::0;;::::1;-1:-1:-1::0;;2601:22:22::1;::::0;::::1;;::::0;::::1;::::0;;;::::1;::::0;::::1;:::i;2502:127::-;1356:1:2;2347:287:22::0;:::o;1404:1088:57:-;1560:12;1584:29;1616:39;1637:17;1616:20;:39::i;:::-;1584:71;-1:-1:-1;1699:7:57;;-1:-1:-1;;;;;;1699:7:57;;;1673:33;;;;;1665:107;;;;-1:-1:-1;;;1665:107:57;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1782:29;;:::i;:::-;-1:-1:-1;1814:148:57;;;;;;;;-1:-1:-1;;;;;1851:19:57;;-1:-1:-1;1851:19:57;;;:6;:19;;;;;;;;;1814:148;;;;;;;;;;;1980:45;1858:11;1814:148;2008:4;2014;2020;1980:6;:45::i;:::-;1972:91;;;;-1:-1:-1;;;1972:91:57;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;;2095:19:57;;;;;;:6;:19;;;;;;:26;;2119:1;2095:23;:26::i;:::-;2073:6;:19;2080:11;-1:-1:-1;;;;;2073:19:57;-1:-1:-1;;;;;2073:19:57;;;;;;;;;;;;:48;;;;2208:12;2222:23;2257:4;-1:-1:-1;;;;;2249:18:57;2285:17;2304:11;2268:48;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;2268:48:57;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;;2268:48:57;;;;;;;;;;;;;;;;;;;;;;;2249:68;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;2249:68:57;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2207:110;;;;2336:7;2328:48;;;;;-1:-1:-1;;;2328:48:57;;;;;;;;;;;;-1:-1:-1;;;2328:48:57;;;;;;;;;;;;;;;2391:67;2415:11;2428:10;2440:17;2391:67;;;;-1:-1:-1;;;;;2391:67:57;;;;;;-1:-1:-1;;;;;2391:67:57;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2475:10;1404:1088;-1:-1:-1;;;;;;;;;1404:1088:57:o;2727:97:7:-;2813:4;2806:11;;;;;;;;-1:-1:-1;;2806:11:7;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2781:13;;2806:11;;2813:4;;2806:11;;2813:4;2806:11;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2727:97;;;:::o;2790:106:57:-;-1:-1:-1;;;;;2877:12:57;2844:13;2877:12;;;:6;:12;;;;;;;2790:106::o;5593:1184:7:-;5847:7;:14;5833:3;:10;:28;5825:81;;;;-1:-1:-1;;;5825:81:7;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;;5924:16:7;;5916:66;;;;-1:-1:-1;;;5916:66:7;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6021:12;:10;:12::i;:::-;-1:-1:-1;;;;;6013:20:7;:4;-1:-1:-1;;;;;6013:20:7;;:60;;;;6037:36;6054:4;6060:12;:10;:12::i;6037:36::-;5992:157;;;;-1:-1:-1;;;5992:157:7;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6160:16;6179:12;:10;:12::i;:::-;6160:31;;6202:60;6223:8;6233:4;6239:2;6243:3;6248:7;6257:4;6202:20;:60::i;:::-;6278:9;6273:349;6297:3;:10;6293:1;:14;6273:349;;;6328:10;6341:3;6345:1;6341:6;;;;;;;;;;;;;;6328:19;;6361:14;6378:7;6386:1;6378:10;;;;;;;;;;;;;;6361:27;;6425:123;6466:6;6425:123;;;;;;;;;;;;;;;;;:9;:13;6435:2;6425:13;;;;;;;;;;;:19;6439:4;-1:-1:-1;;;;;6425:19:7;-1:-1:-1;;;;;6425:19:7;;;;;;;;;;;;;:23;;:123;;;;;:::i;:::-;6403:13;;;;:9;:13;;;;;;;;-1:-1:-1;;;;;6403:19:7;;;;;;;;;;:145;;;;6582:17;;;;;;:29;;6604:6;6582:21;:29::i;:::-;6562:13;;;;:9;:13;;;;;;;;-1:-1:-1;;;;;6562:17:7;;;;;;;;;;:49;-1:-1:-1;6309:3:7;6273:349;;;;6667:2;-1:-1:-1;;;;;6637:47:7;6661:4;-1:-1:-1;;;;;6637:47:7;6651:8;-1:-1:-1;;;;;6637:47:7;;6671:3;6676:7;6637:47;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6695:75;6731:8;6741:4;6747:2;6751:3;6756:7;6765:4;6695:35;:75::i;:::-;5593:1184;;;;;;:::o;4665:426:22:-;4766:23;4792:13;;;:7;:13;;;;;4819:11;;;;:20;4811:49;;;;-1:-1:-1;;;4811:49:22;;;;;;;:::i;:::-;4881:52;4899:7;4908:11;:9;:11::i;:::-;4921:5;:11;;;4881:17;:52::i;:::-;4866:123;;;;-1:-1:-1;;;4866:123:22;;;;;;;:::i;:::-;4995:35;5001:7;5010:5;:11;;;5023:6;4995:5;:35::i;:::-;5058:19;;;;:28;;;;5036:50;;-1:-1:-1;;4665:426:22:o;5987:270::-;6056:7;6106:13;;;:7;:13;;;;;6129:11;;6056:7;;6106:13;6129:11;;6125:89;;;6158:11;;;;6185:17;;;;;6158:11;;-1:-1:-1;6171:31:22;;-1:-1:-1;;6171:35:22;;-1:-1:-1;6150:57:22;;6125:89;6227:11;;;;-1:-1:-1;6227:11:22;;-1:-1:-1;5987:270:22;;;;:::o;3343:615:7:-;3500:16;3559:3;:10;3540:8;:15;:29;3532:83;;;;-1:-1:-1;;;3532:83:7;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;3626:30;3673:8;:15;-1:-1:-1;;;;;3659:30:7;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;3659:30:7;;3626:63;;3705:9;3700:221;3724:8;:15;3720:1;:19;3700:221;;;3791:1;-1:-1:-1;;;;;3768:25:7;:8;3777:1;3768:11;;;;;;;;;;;;;;-1:-1:-1;;;;;3768:25:7;;;3760:87;;;;-1:-1:-1;;;3760:87:7;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;3880:9;:17;3890:3;3894:1;3890:6;;;;;;;;;;;;;;3880:17;;;;;;;;;;;:30;3898:8;3907:1;3898:11;;;;;;;;;;;;;;-1:-1:-1;;;;;3880:30:7;-1:-1:-1;;;;;3880:30:7;;;;;;;;;;;;;3861:13;3875:1;3861:16;;;;;;;;;;;;;;;;;:49;3741:3;;3700:221;;;-1:-1:-1;3938:13:7;3343:615;-1:-1:-1;;;3343:615:7:o;6300:303:22:-;6384:4;6422:13;;;:7;:13;;;;;6446:11;;;;6441:84;;6489:2;6474:5;:11;;;:17;:44;;;;;6517:1;6495:5;:19;;;:23;6474:44;6467:51;;;;;6441:84;6552:2;6537:5;:11;;;:17;;:61;;;;;6578:5;:19;;;6564:5;:11;;;:33;6558:2;:40;6537:61;6530:68;6300:303;-1:-1:-1;;;;6300:303:22:o;2638:260::-;2710:4;2748:13;;;:7;:13;;;;;2775:15;;;2710:4;2791:11;:9;:11::i;:::-;-1:-1:-1;;;;;2775:28:22;;;;;;;;;;;;-1:-1:-1;2775:28:22;;;;2767:70;;;;-1:-1:-1;;;2767:70:22;;;;;;;:::i;:::-;-1:-1:-1;;;;;2843:26:22;;;;;;:15;;;;:26;;;;;:33;;-1:-1:-1;;2843:33:22;2872:4;2843:33;;;;;;2872:4;-1:-1:-1;2638:260:22;;;;:::o;1706:145:2:-;1297:12;:10;:12::i;:::-;1287:6;;-1:-1:-1;;;;;1287:6:2;;;:22;;;1279:67;;;;;-1:-1:-1;;;1279:67:2;;;;;;;;;;;;;-1:-1:-1;;;;;;;;;;;1279:67:2;;;;;;;;;;;;;;;1796:6:::1;::::0;1775:40:::1;::::0;1812:1:::1;::::0;-1:-1:-1;;;;;1796:6:2::1;::::0;-1:-1:-1;;;;;;;;;;;1775:40:2;1812:1;;1775:40:::1;1825:6;:19:::0;;-1:-1:-1;;;;;;1825:19:2::1;::::0;;1706:145::o;5237:230:22:-;5357:4;5376:35;5393:7;5402:8;5376:16;:35::i;:::-;:86;;;;5428:8;-1:-1:-1;;;;;5417:19:22;:7;-1:-1:-1;;;;;5417:19:22;;:43;;;;;5440:20;5448:7;5457:2;5440:7;:20::i;1083:77:2:-;1147:6;;-1:-1:-1;;;;;1147:6:2;1083:77;;:::o;6873:330:22:-;-1:-1:-1;;;;;6996:23:22;;6975:18;6996:23;;;:14;:23;;;;;6951:16;;6975:18;6996:32;;:30;:32::i;:::-;6975:53;;7035:20;7072:10;-1:-1:-1;;;;;7058:25:22;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;7058:25:22;;7035:48;;7094:9;7089:94;7113:10;7109:1;:14;7089:94;;;-1:-1:-1;;;;;7147:23:22;;;;;;:14;:23;;;;;:29;;7174:1;7147:26;:29::i;:::-;7138:3;7142:1;7138:6;;;;;;;;;;;;;;;;;:38;7125:3;;7089:94;;4026:306:7;4144:8;-1:-1:-1;;;;;4128:24:7;:12;:10;:12::i;:::-;-1:-1:-1;;;;;4128:24:7;;;4120:78;;;;-1:-1:-1;;;4120:78:7;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4254:8;4209:18;:32;4228:12;:10;:12::i;:::-;-1:-1:-1;;;;;4209:32:7;;;;;;;;;;;;;;;;;-1:-1:-1;4209:32:7;;;:42;;;;;;;;;;;;:53;;-1:-1:-1;;4209:53:7;;;;;;;;;;;4292:12;:10;:12::i;:::-;-1:-1:-1;;;;;4277:48:7;;4316:8;4277:48;;;;;;;;;;;;;;;;;;;;4026:306;;:::o;6607:127:22:-;6682:7;6704:13;;;:7;:13;;;;;:25;;;;6607:127::o;5532:451::-;5636:7;:14;5601:7;;-1:-1:-1;;5636:18:22;5601:7;5660:319;5685:9;5680:1;:14;5660:319;;5718:9;5713:1;:14;5709:264;;;5739:27;5769:7;:23;5777:11;5789:1;5777:14;;;;;;;;;;;;;;;;5769:23;;;;;;;;;;;5739:53;;5812:17;5819:9;5812:6;:17::i;:::-;5806:2;:23;5802:73;;5850:11;5862:1;5850:14;;;;;;;;;;;;;;;;5843:21;;;;;;;5802:73;5709:264;;;;5906:2;5892:7;5900:1;5892:10;;;;;;;;;;;;;;;;:16;;:39;;;;;5917:7;5925:1;5929;5925:5;5917:14;;;;;;;;;;;;;;;;5912:2;:19;5892:39;5889:84;;;5950:11;5962:1;5950:14;;;;;;;;;;;;;;;;5943:21;;;;;;5889:84;5696:3;;5660:319;;;;5532:451;;;;:::o;6738:131::-;6815:7;6837:13;;;:7;:13;;;;;:27;;;;6738:131::o;4316:343::-;4436:4;4448:12;4463:13;4473:2;4463:9;:13::i;:::-;4482:23;4508:13;;;:7;:13;;;;;4448:28;;-1:-1:-1;4535:15:22;;;;4551:11;:9;:11::i;:::-;-1:-1:-1;;;;;4535:28:22;;;;;;;;;;;;-1:-1:-1;4535:28:22;;;;4527:72;;;;-1:-1:-1;;;4527:72:22;;;;;;;:::i;:::-;4605:32;4611:7;4620:2;4624:6;4632:4;4605:5;:32::i;:::-;-1:-1:-1;4650:4:22;;4316:343;-1:-1:-1;;;;;;4316:343:22:o;687:41::-;;;:::o;3169:866::-;3319:23;3345:13;;;:7;:13;;;;;3295:16;;3372:15;;;;3388:11;:9;:11::i;:::-;-1:-1:-1;;;;;3372:28:22;;;;;;;;;;;;-1:-1:-1;3372:28:22;;;;3364:71;;;;-1:-1:-1;;;3364:71:22;;;;;;;:::i;:::-;3483:5;:17;;;3472:6;3450:5;:19;;;:28;3449:51;;3441:94;;;;-1:-1:-1;;;3441:94:22;;;;;;;:::i;:::-;3579:11;;3542:26;;3579:11;;3575:377;;;3626:6;-1:-1:-1;;;;;3612:21:22;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;3612:21:22;;3600:33;;3646:6;3641:173;3658:6;3654:1;:10;3641:173;;;3681:62;3687:7;3732:1;3710:5;:19;;;3696:5;:11;;;:33;:37;3735:1;3738:4;3681:5;:62::i;:::-;3804:1;3782:5;:19;;;3768:5;:11;;;:33;:37;3753:9;3763:1;3753:12;;;;;;;;;;;;;;;;;:52;3666:3;;3641:173;;;;3575:377;;;3846:16;;;3860:1;3846:16;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;3846:16:22;3834:28;;3885:5;:11;;;3870:9;3880:1;3870:12;;;;;;;;;;;;;:26;;;;;3904:41;3910:7;3919:5;:11;;;3932:6;3940:4;3904:5;:41::i;:::-;3980:19;;;;;;:28;;3958:50;;4021:9;-1:-1:-1;3169:866:22;;;;;;:::o;5095:138::-;5183:4;5227:1;5202:22;5212:7;5221:2;5202:9;:22::i;:::-;:26;;5095:138;-1:-1:-1;;;5095:138:22:o;1392:951::-;1297:12:2;:10;:12::i;:::-;1287:6;;-1:-1:-1;;;;;1287:6:2;;;:22;;;1279:67;;;;;-1:-1:-1;;;1279:67:2;;;;;;;;;;;;;-1:-1:-1;;;;;;;;;;;1279:67:2;;;;;;;;;;;;;;;1553:1:22::1;1539:11;:15;1531:63;;;;-1:-1:-1::0;;;1531:63:22::1;;;;;;;:::i;:::-;1624:11;:18:::0;1601:13:::1;::::0;1620:257:::1;;-1:-1:-1::0;1665:1:22::1;1620:257;;;1695:13;::::0;;;:7:::1;:13;::::0;;;;:25:::1;;::::0;:30;1687:67:::1;;;;-1:-1:-1::0;;;1687:67:22::1;;;;;;;:::i;:::-;1814:52;1821:7;:44;1829:11;1862:1;1841:11;:18;;;;:22;1829:35;;;;;;;;;;;;;;;;1821:44;;;;;;;;;;;1814:6;:52::i;:::-;1869:1;1814:56;1806:64;;1620:257;1883:23;1909:13:::0;;;:7:::1;:13;::::0;;;;1928:19;;-1:-1:-1;;1928:19:22::1;::::0;::::1;;;::::0;;-1:-1:-1;1953:11:22;::::1;:19:::0;;;1978:17:::1;::::0;::::1;:31:::0;;;2015:19:::1;::::0;::::1;:23:::0;;;1909:13;2045:95:::1;2066:9;:16;2062:1;:20;2045:95;;;2129:4;2097:5;:15;;:29;2113:9;2123:1;2113:12;;;;;;;;;::::0;;::::1;::::0;;;;;;;-1:-1:-1;;;;;2097:29:22::1;::::0;;;::::1;::::0;;;;;;-1:-1:-1;2097:29:22;:36;;-1:-1:-1;;2097:36:22::1;::::0;::::1;;::::0;;;::::1;::::0;;-1:-1:-1;2084:3:22::1;2045:95;;;-1:-1:-1::0;2149:16:22;;2145:77:::1;;2211:4;2180:5;:15;;:28;2196:11;:9;:11::i;:::-;-1:-1:-1::0;;;;;2180:28:22::1;::::0;;::::1;::::0;::::1;::::0;;;;;;-1:-1:-1;2180:28:22;:35;;-1:-1:-1;;2180:35:22::1;::::0;::::1;;::::0;;;::::1;::::0;;2145:77:::1;-1:-1:-1::0;;2236:13:22::1;2243:5;2236:6;:13::i;:::-;:33;2228:56;;;;-1:-1:-1::0;;;2228:56:22::1;;;;;;;:::i;:::-;-1:-1:-1::0;2291:11:22::1;:22:::0;;::::1;::::0;;::::1;::::0;;;;::::1;::::0;;;;2319:7:::1;:19:::0;;;;::::1;::::0;;-1:-1:-1;2319:19:22;;;;::::1;::::0;;;;-1:-1:-1;;;1392:951:22:o;4399:158:7:-;-1:-1:-1;;;;;4513:27:7;;;4490:4;4513:27;;;:18;:27;;;;;;;;:37;;;;;;;;;;;;;;;4399:158::o;8010:640:22:-;8144:6;8166:10;-1:-1:-1;;;;;8188:16:22;8166:39;;8158:103;;;;-1:-1:-1;;;8158:103:22;;;;;;;:::i;:::-;8268:18;8288:16;8308;-1:-1:-1;;;;;8308:24:22;;-1:-1:-1;;;8308:55:22;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;8267:96;;;;8383:13;8377:2;:19;;:40;;;;;8406:11;8400:2;:17;;8377:40;8369:92;;;;-1:-1:-1;;;8369:92:22;;;;;;;:::i;:::-;-1:-1:-1;;;8472:26:22;8501:38;;;:7;:38;;;;8558:14;;8501:38;8546;;;;;;;;;;8501;;8546;;8552:4;;8558:14;8574:5;;8546;:38::i;:::-;-1:-1:-1;;;;8602:43:22;8010:640;-1:-1:-1;;;;;;;;;8010:640:22:o;4624:897:7:-;-1:-1:-1;;;;;4839:16:7;;4831:66;;;;-1:-1:-1;;;4831:66:7;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4936:12;:10;:12::i;:::-;-1:-1:-1;;;;;4928:20:7;:4;-1:-1:-1;;;;;4928:20:7;;:60;;;;4952:36;4969:4;4975:12;:10;:12::i;4952:36::-;4907:148;;;;-1:-1:-1;;;4907:148:7;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;5066:16;5085:12;:10;:12::i;:::-;5066:31;;5108:96;5129:8;5139:4;5145:2;5149:21;5167:2;5149:17;:21::i;:::-;5172:25;5190:6;5172:17;:25::i;:::-;5199:4;5108:20;:96::i;:::-;5237:77;5261:6;5237:77;;;;;;;;;;;;;;;;;:13;;;;:9;:13;;;;;;;;-1:-1:-1;;;;;5237:19:7;;;;;;;;;;;:77;:23;:77::i;:::-;5215:13;;;;:9;:13;;;;;;;;-1:-1:-1;;;;;5215:19:7;;;;;;;;;;:99;;;;5344:17;;;;;;:29;;5366:6;5344:21;:29::i;:::-;5324:13;;;;:9;:13;;;;;;;;-1:-1:-1;;;;;5324:17:7;;;;;;;;;;;;;:49;;;;5389:46;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;;;;;;;;5389:46:7;;;;;;;;5446:68;5477:8;5487:4;5493:2;5497;5501:6;5509:4;5446:30;:68::i;2000:240:2:-;1297:12;:10;:12::i;:::-;1287:6;;-1:-1:-1;;;;;1287:6:2;;;:22;;;1279:67;;;;;-1:-1:-1;;;1279:67:2;;;;;;;;;;;;;-1:-1:-1;;;;;;;;;;;1279:67:2;;;;;;;;;;;;;;;-1:-1:-1;;;;;2088:22:2;::::1;2080:73;;;;-1:-1:-1::0;;;2080:73:2::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2189:6;::::0;2168:38:::1;::::0;-1:-1:-1;;;;;2168:38:2;;::::1;::::0;2189:6:::1;::::0;-1:-1:-1;;;;;;;;;;;2168:38:2;2189:6:::1;::::0;2168:38:::1;2216:6;:17:::0;;-1:-1:-1;;;;;;2216:17:2::1;-1:-1:-1::0;;;;;2216:17:2;;;::::1;::::0;;;::::1;::::0;;2000:240::o;3350:534:57:-;3393:22;3430:10;3452:4;3430:27;3427:428;;;3473:18;3494:8;;3473:29;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;3532:8:57;3718:17;3712:24;-1:-1:-1;;;;;3708:73:57;;-1:-1:-1;3570:225:57;;-1:-1:-1;3570:225:57;;-1:-1:-1;3834:10:57;3350:534;:::o;7207:153:22:-;7292:15;7322:33;:31;:33::i;:::-;7315:40;;7207:153;:::o;1150:248:57:-;1225:16;1257:7;:14;1275:1;1257:19;1253:60;;;-1:-1:-1;1299:3:57;1292:10;;1253:60;-1:-1:-1;1378:2:57;1365:16;1359:23;;1332:60::o;2902:331::-;3026:4;3042:14;3059:76;3069:47;3088:27;3108:6;3088:19;:27::i;:::-;3069:18;:47::i;:::-;3118:4;3124;3130;3059:76;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;3059:76:57;;-1:-1:-1;;3059:76:57;;;-1:-1:-1;;;;;;;3153:20:57;;3145:50;;;;;-1:-1:-1;;;3145:50:57;;;;;;;;;;;;-1:-1:-1;;;3145:50:57;;;;;;;;;;;;;;;3222:4;-1:-1:-1;;;;;3212:14:57;:6;-1:-1:-1;;;;;3212:14:57;;3205:21;;;2902:331;;;;;;;:::o;882:176:6:-;940:7;971:5;;;994:6;;;;986:46;;;;;-1:-1:-1;;;986:46:6;;;;;;;;;;;;-1:-1:-1;;;986:46:6;;;;;;;;;;;;;;;1050:1;882:176;-1:-1:-1;;;882:176:6:o;7565:441:22:-;7749:9;7744:258;7768:3;:10;7764:1;:14;7744:258;;;-1:-1:-1;;;;;7797:18:22;;;;;;:65;;;7861:1;7846:7;7854:1;7846:10;;;;;;;;;;;;;;7820:23;7830:4;7836:3;7840:1;7836:6;;;;;;;;;;;;;;7820:9;:23::i;:::-;:36;7819:43;;7797:65;7793:125;;;7874:35;7902:3;7906:1;7902:6;;;;;;;;;;;;;;7874:14;:20;7889:4;-1:-1:-1;;;;;7874:20:22;-1:-1:-1;;;;;7874:20:22;;;;;;;;;;;;:27;;:35;;;;:::i;:::-;;7793:125;-1:-1:-1;;;;;7929:16:22;;;7925:71;;7957:30;7980:3;7984:1;7980:6;;;;;;;;;;;;;;7957:14;:18;7972:2;-1:-1:-1;;;;;7957:18:22;-1:-1:-1;;;;;7957:18:22;;;;;;;;;;;;:22;;:30;;;;:::i;:::-;;7925:71;7780:3;;7744:258;;;;7565:441;;;;;;:::o;1754:187:6:-;1840:7;1875:12;1867:6;;;;1859:29;;;;-1:-1:-1;;;1859:29:6;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;1910:5:6;;;1754:187::o;13286:778:7:-;13530:15;:2;-1:-1:-1;;;;;13530:13:7;;:15::i;:::-;13526:532;;;13582:2;-1:-1:-1;;;;;13565:43:7;;13609:8;13619:4;13625:3;13630:7;13639:4;13565:79;;;;;;;;;;;;;-1:-1:-1;;;;;13565:79:7;;;;;;-1:-1:-1;;;;;13565:79:7;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;13565:79:7;;;13561:487;;;;:::i;:::-;;;;;;;;13917:14;;-1:-1:-1;;;13917:14:7;;;;;;;;;;;;;;;;;13924:6;;13917:14;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;13561:487;13971:62;;-1:-1:-1;;;13971:62:7;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;13561:487;-1:-1:-1;;;;;;13693:64:7;;-1:-1:-1;;;13693:64:7;13689:161;;13781:50;;-1:-1:-1;;;13781:50:7;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;9935:538;-1:-1:-1;;;;;10030:21:7;;10022:69;;;;-1:-1:-1;;;10022:69:7;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;10102:16;10121:12;:10;:12::i;:::-;10102:31;;10144:105;10165:8;10175:7;10192:1;10196:21;10214:2;10196:17;:21::i;:::-;10219:25;10237:6;10219:17;:25::i;:::-;10144:105;;;;;;;;;;;;:20;:105::i;:::-;10285:108;10325:6;10285:108;;;;;;;;;;;;;;;;;:13;;;;:9;:13;;;;;;;;-1:-1:-1;;;;;10285:22:7;;;;;;;;;;;:108;:26;:108::i;:::-;10260:13;;;;:9;:13;;;;;;;;-1:-1:-1;;;;;10260:22:7;;;;;;;;;;;;:133;;;;10409:57;;;;;;;;;;;;;10260:13;;:22;;10409:57;;;;-1:-1:-1;;;;;;;;;;;10409:57:7;;;;;;;;9935:538;;;;:::o;8770:112:17:-;8830:7;8856:19;8864:3;8856:7;:19::i;9214:135::-;9285:7;9319:22;9323:3;9335:5;9319:3;:22::i;7364:197:22:-;7454:11;;7435:7;;7454:11;;7450:59;;-1:-1:-1;7491:11:22;;;;7484:18;;7450:59;7555:1;7535:5;:17;;;7521:5;:11;;;:31;:35;7514:42;;7364:197;;;:::o;8069:572:7:-;-1:-1:-1;;;;;8183:21:7;;8175:67;;;;-1:-1:-1;;;8175:67:7;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8253:16;8272:12;:10;:12::i;:::-;8253:31;;8295:107;8316:8;8334:1;8338:7;8347:21;8365:2;8347:17;:21::i;8295:107::-;8438:13;;;;:9;:13;;;;;;;;-1:-1:-1;;;;;8438:22:7;;;;;;;;;;:34;;8465:6;8438:26;:34::i;:::-;8413:13;;;;:9;:13;;;;;;;;-1:-1:-1;;;;;8413:22:7;;;;;;;;;;;;:59;;;;8487:57;;;;;;;;;;;;;8413:22;;8487:57;;;-1:-1:-1;;;;;;;;;;;8487:57:7;;;;;;;;8555:79;8586:8;8604:1;8608:7;8617:2;8621:6;8629:4;8555:30;:79::i;:::-;8069:572;;;;;:::o;14070:193::-;14189:16;;;14203:1;14189:16;;;;;;;;;14136;;;;14189;;;;;;;;;;;;-1:-1:-1;14189:16:7;14164:41;;14226:7;14215:5;14221:1;14215:8;;;;;;;;;;;;;;;;;:18;14251:5;14070:193;-1:-1:-1;;14070:193:7:o;12539:741::-;12758:15;:2;-1:-1:-1;;;;;12758:13:7;;:15::i;:::-;12754:520;;;12810:2;-1:-1:-1;;;;;12793:38:7;;12832:8;12842:4;12848:2;12852:6;12860:4;12793:72;;;;;;;;;;;;;-1:-1:-1;;;;;12793:72:7;;;;;;-1:-1:-1;;;;;12793:72:7;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;12793:72:7;;;12789:475;;;;:::i;:::-;-1:-1:-1;;;;;;12914:59:7;;-1:-1:-1;;;12914:59:7;12910:156;;12997:50;;-1:-1:-1;;;12997:50:7;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2498:286:57;2581:7;460:76;;;;;;;;;;;;;;;;;450:87;;;;;;2680:6;:12;;;2706:6;:11;;;2741:6;:24;;;2731:35;;;;;;2617:159;;;;;;;;;;;;;;;;-1:-1:-1;;;;;2617:159:57;;;;;;;;;;;;;;;;;;;;;;;;;;;;2607:170;;;;;;2600:177;;2498:286;;;:::o;1380:178:56:-;1451:7;1516:20;:18;:20::i;:::-;1538:11;1487:63;;;;;;-1:-1:-1;;;1487:63:56;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1477:74;;;;;;1470:81;;1380:178;;;:::o;8329:135:17:-;8399:4;8422:35;8430:3;8450:5;8422:7;:35::i;8032:129::-;8099:4;8122:32;8127:3;8147:5;8122:4;:32::i;726:413:15:-;1086:20;1124:8;;;726:413::o;4013:107:17:-;4095:18;;4013:107::o;4452:201::-;4546:18;;4519:7;;4546:26;-1:-1:-1;4538:73:17;;;;-1:-1:-1;;;4538:73:17;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4628:3;:11;;4640:5;4628:18;;;;;;;;;;;;;;;;4621:25;;4452:201;;;;:::o;927:99:56:-;1004:15;;927:99;:::o;2212:1512:17:-;2278:4;2415:19;;;:12;;;:19;;;;;;2449:15;;2445:1273;;2878:18;;-1:-1:-1;;2830:14:17;;;;2878:22;;;;2806:21;;2878:3;;:22;;3160;;;;;;;;;;;;;;3140:42;;3303:9;3274:3;:11;;3286:13;3274:26;;;;;;;;;;;;;;;;;;;:38;;;;3378:23;;;3420:1;3378:12;;;:23;;;;;;3404:17;;;3378:43;;3527:17;;3378:3;;3527:17;;;;;;;;;;;;;;;;;;;;;;3619:3;:12;;:19;3632:5;3619:19;;;;;;;;;;;3612:26;;;3660:4;3653:11;;;;;;;;2445:1273;3702:5;3695:12;;;;;1640:404;1703:4;1724:21;1734:3;1739:5;1724:9;:21::i;:::-;1719:319;;-1:-1:-1;1761:23:17;;;;;;;;:11;:23;;;;;;;;;;;;;1941:18;;1919:19;;;:12;;;:19;;;;;;:40;;;;1973:11;;1719:319;-1:-1:-1;2022:5:17;2015:12;;3805:127;3878:4;3901:19;;;:12;;;;;:19;;;;;;:24;;;3805:127::o;-1:-1:-1:-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;14:769:59:-;;127:3;120:4;112:6;108:17;104:27;94:2;;149:5;142;135:20;94:2;193:6;180:20;218:69;233:53;279:6;233:53;:::i;:::-;218:69;:::i;:::-;321:21;;;209:78;-1:-1:-1;361:4:59;381:14;;;;415:15;;;461;;;449:28;;445:37;;442:46;-1:-1:-1;439:2:59;;;501:1;498;491:12;439:2;523:1;533:244;547:6;544:1;541:13;533:244;;;622:3;609:17;639:33;666:5;639:33;:::i;:::-;685:18;;723:12;;;;755;;;;569:1;562:9;533:244;;;537:3;;;;;84:699;;;;:::o;788:692::-;;901:3;894:4;886:6;882:17;878:27;868:2;;923:5;916;909:20;868:2;967:6;954:20;992:69;1007:53;1053:6;1007:53;:::i;992:69::-;1095:21;;;983:78;-1:-1:-1;1135:4:59;1155:14;;;;1189:15;;;1235;;;1223:28;;1219:37;;1216:46;-1:-1:-1;1213:2:59;;;1275:1;1272;1265:12;1213:2;1297:1;1307:167;1321:6;1318:1;1315:13;1307:167;;;1382:17;;1370:30;;1420:12;;;;1452;;;;1343:1;1336:9;1307:167;;1485:521;;1582:3;1575:4;1567:6;1563:17;1559:27;1549:2;;1604:5;1597;1590:20;1549:2;1635:20;;-1:-1:-1;;;;;1667:30:59;;1664:2;;;1700:9;1664:2;1729:58;1775:2;1752:17;;-1:-1:-1;;1748:31:59;1781:4;1744:42;1729:58;:::i;:::-;1720:67;;1810:6;1803:5;1796:21;1864:3;1857:4;1848:6;1840;1836:19;1832:30;1829:39;1826:2;;;1881:1;1878;1871:12;1826:2;1944:6;1937:4;1929:6;1925:17;1918:4;1911:5;1907:16;1894:57;1998:1;1971:18;;;1991:4;1967:29;1960:40;1975:5;1539:467;-1:-1:-1;;1539:467:59:o;2011:259::-;;2123:2;2111:9;2102:7;2098:23;2094:32;2091:2;;;2144:6;2136;2129:22;2091:2;2188:9;2175:23;2207:33;2234:5;2207:33;:::i;2275:402::-;;;2404:2;2392:9;2383:7;2379:23;2375:32;2372:2;;;2425:6;2417;2410:22;2372:2;2469:9;2456:23;2488:33;2515:5;2488:33;:::i;:::-;2540:5;-1:-1:-1;2597:2:59;2582:18;;2569:32;2610:35;2569:32;2610:35;:::i;:::-;2664:7;2654:17;;;2362:315;;;;;:::o;2682:1129::-;;;;;;2921:3;2909:9;2900:7;2896:23;2892:33;2889:2;;;2943:6;2935;2928:22;2889:2;2987:9;2974:23;3006:33;3033:5;3006:33;:::i;:::-;3058:5;-1:-1:-1;3115:2:59;3100:18;;3087:32;3128:35;3087:32;3128:35;:::i;:::-;3182:7;-1:-1:-1;3240:2:59;3225:18;;3212:32;-1:-1:-1;;;;;3293:14:59;;;3290:2;;;3325:6;3317;3310:22;3290:2;3353:67;3412:7;3403:6;3392:9;3388:22;3353:67;:::i;:::-;3343:77;;3473:2;3462:9;3458:18;3445:32;3429:48;;3502:2;3492:8;3489:16;3486:2;;;3523:6;3515;3508:22;3486:2;3551:69;3612:7;3601:8;3590:9;3586:24;3551:69;:::i;:::-;3541:79;;3673:3;3662:9;3658:19;3645:33;3629:49;;3703:2;3693:8;3690:16;3687:2;;;3724:6;3716;3709:22;3687:2;;3752:53;3797:7;3786:8;3775:9;3771:24;3752:53;:::i;:::-;3742:63;;;2879:932;;;;;;;;:::o;3816:470::-;;;;3962:2;3950:9;3941:7;3937:23;3933:32;3930:2;;;3983:6;3975;3968:22;3930:2;4027:9;4014:23;4046:33;4073:5;4046:33;:::i;:::-;4098:5;-1:-1:-1;4155:2:59;4140:18;;4127:32;4168:35;4127:32;4168:35;:::i;:::-;3920:366;;4222:7;;-1:-1:-1;;;4276:2:59;4261:18;;;;4248:32;;3920:366::o;4291:1059::-;;;;;;;4490:3;4478:9;4469:7;4465:23;4461:33;4458:2;;;4512:6;4504;4497:22;4458:2;4556:9;4543:23;4575:33;4602:5;4575:33;:::i;:::-;4627:5;-1:-1:-1;4684:2:59;4669:18;;4656:32;4697:35;4656:32;4697:35;:::i;:::-;4751:7;-1:-1:-1;4805:2:59;4790:18;;4777:32;;-1:-1:-1;4856:2:59;4841:18;;4828:32;;-1:-1:-1;4911:3:59;4896:19;;4883:33;-1:-1:-1;;;;;4965:14:59;;;4962:2;;;4997:6;4989;4982:22;4962:2;5040:6;5029:9;5025:22;5015:32;;5085:7;5078:4;5074:2;5070:13;5066:27;5056:2;;5112:6;5104;5097:22;5056:2;5157;5144:16;5183:2;5175:6;5172:14;5169:2;;;5204:6;5196;5189:22;5169:2;5254:7;5249:2;5240:6;5236:2;5232:15;5228:24;5225:37;5222:2;;;5280:6;5272;5265:22;5222:2;5316;5312;5308:11;5298:21;;5338:6;5328:16;;;;;4448:902;;;;;;;;:::o;5355:760::-;;;;;;5544:3;5532:9;5523:7;5519:23;5515:33;5512:2;;;5566:6;5558;5551:22;5512:2;5610:9;5597:23;5629:33;5656:5;5629:33;:::i;:::-;5681:5;-1:-1:-1;5738:2:59;5723:18;;5710:32;5751:35;5710:32;5751:35;:::i;:::-;5805:7;-1:-1:-1;5859:2:59;5844:18;;5831:32;;-1:-1:-1;5910:2:59;5895:18;;5882:32;;-1:-1:-1;5965:3:59;5950:19;;5937:33;-1:-1:-1;;;;;5982:30:59;;5979:2;;;6030:6;6022;6015:22;5979:2;6058:51;6101:7;6092:6;6081:9;6077:22;6058:51;:::i;6120:396::-;;;6246:2;6234:9;6225:7;6221:23;6217:32;6214:2;;;6267:6;6259;6252:22;6214:2;6311:9;6298:23;6330:33;6357:5;6330:33;:::i;:::-;6382:5;-1:-1:-1;6439:2:59;6424:18;;6411:32;6452;6411;6452;:::i;6521:327::-;;;6650:2;6638:9;6629:7;6625:23;6621:32;6618:2;;;6671:6;6663;6656:22;6618:2;6715:9;6702:23;6734:33;6761:5;6734:33;:::i;:::-;6786:5;6838:2;6823:18;;;;6810:32;;-1:-1:-1;;;6608:240:59:o;6853:395::-;;;;6999:2;6987:9;6978:7;6974:23;6970:32;6967:2;;;7020:6;7012;7005:22;6967:2;7064:9;7051:23;7083:33;7110:5;7083:33;:::i;:::-;7135:5;7187:2;7172:18;;7159:32;;-1:-1:-1;7238:2:59;7223:18;;;7210:32;;6957:291;-1:-1:-1;;;6957:291:59:o;7253:616::-;;;;;7425:3;7413:9;7404:7;7400:23;7396:33;7393:2;;;7447:6;7439;7432:22;7393:2;7491:9;7478:23;7510:33;7537:5;7510:33;:::i;:::-;7562:5;-1:-1:-1;7614:2:59;7599:18;;7586:32;;-1:-1:-1;7665:2:59;7650:18;;7637:32;;-1:-1:-1;7720:2:59;7705:18;;7692:32;-1:-1:-1;;;;;7736:30:59;;7733:2;;;7784:6;7776;7769:22;7733:2;7812:51;7855:7;7846:6;7835:9;7831:22;7812:51;:::i;:::-;7802:61;;;7383:486;;;;;;;:::o;7874:792::-;;;;;;8061:3;8049:9;8040:7;8036:23;8032:33;8029:2;;;8083:6;8075;8068:22;8029:2;8127:9;8114:23;8146:33;8173:5;8146:33;:::i;:::-;8198:5;-1:-1:-1;8254:2:59;8239:18;;8226:32;-1:-1:-1;;;;;8270:30:59;;8267:2;;;8318:6;8310;8303:22;8267:2;8346:51;8389:7;8380:6;8369:9;8365:22;8346:51;:::i;:::-;8336:61;;;8444:2;8433:9;8429:18;8416:32;8406:42;;8495:2;8484:9;8480:18;8467:32;8457:42;;8551:3;8540:9;8536:19;8523:33;8600:4;8591:7;8587:18;8578:7;8575:31;8565:2;;8625:6;8617;8610:22;8565:2;8653:7;8643:17;;;8019:647;;;;;;;;:::o;9624:1040::-;;9750:2;9793;9781:9;9772:7;9768:23;9764:32;9761:2;;;9814:6;9806;9799:22;9761:2;9846:16;;-1:-1:-1;;;;;9874:30:59;;9871:2;;;9922:6;9914;9907:22;9871:2;9950:22;;10003:4;9995:13;;9991:27;-1:-1:-1;9981:2:59;;10037:6;10029;10022:22;9981:2;10075;10069:9;10098:69;10113:53;10159:6;10113:53;:::i;10098:69::-;10201:19;;;10236:12;;;;10268:11;;;10306:15;;;10298:24;;10294:33;;10291:46;-1:-1:-1;10288:2:59;;;10355:6;10347;10340:22;10288:2;10382:6;10373:15;;10397:237;10411:6;10408:1;10405:13;10397:237;;;10479:3;10473:10;10496:33;10523:5;10496:33;:::i;:::-;10542:18;;10433:1;10426:9;;;;;10580:12;;;;10612;;10397:237;;;-1:-1:-1;10653:5:59;9730:934;-1:-1:-1;;;;;;;9730:934:59:o;10669:637::-;;;10848:2;10836:9;10827:7;10823:23;10819:32;10816:2;;;10869:6;10861;10854:22;10816:2;10901:23;;-1:-1:-1;;;;;10973:14:59;;;10970:2;;;11005:6;10997;10990:22;10970:2;11033:67;11092:7;11083:6;11072:9;11068:22;11033:67;:::i;:::-;11023:77;;11153:2;11142:9;11138:18;11125:32;11109:48;;11182:2;11172:8;11169:16;11166:2;;;11203:6;11195;11188:22;11166:2;;11231:69;11292:7;11281:8;11270:9;11266:24;11231:69;:::i;:::-;11221:79;;;10806:500;;;;;:::o;11311:257::-;;11431:2;11419:9;11410:7;11406:23;11402:32;11399:2;;;11452:6;11444;11437:22;11399:2;11489:9;11483:16;11508:30;11532:5;11508:30;:::i;11573:190::-;;11685:2;11673:9;11664:7;11660:23;11656:32;11653:2;;;11706:6;11698;11691:22;11653:2;-1:-1:-1;11734:23:59;;11643:120;-1:-1:-1;11643:120:59:o;11768:194::-;;11891:2;11879:9;11870:7;11866:23;11862:32;11859:2;;;11912:6;11904;11897:22;11859:2;-1:-1:-1;11940:16:59;;11849:113;-1:-1:-1;11849:113:59:o;11967:642::-;;;;;12152:3;12140:9;12131:7;12127:23;12123:33;12120:2;;;12174:6;12166;12159:22;12120:2;12215:9;12202:23;12192:33;;12275:2;12264:9;12260:18;12247:32;12288:30;12312:5;12288:30;:::i;:::-;12337:5;-1:-1:-1;12389:2:59;12374:18;;12361:32;;-1:-1:-1;12444:2:59;12429:18;;12416:32;-1:-1:-1;;;;;12460:30:59;;12457:2;;;12508:6;12500;12493:22;12457:2;12536:67;12595:7;12586:6;12575:9;12571:22;12536:67;:::i;12614:258::-;;;12743:2;12731:9;12722:7;12718:23;12714:32;12711:2;;;12764:6;12756;12749:22;12711:2;-1:-1:-1;;12792:23:59;;;12862:2;12847:18;;;12834:32;;-1:-1:-1;12701:171:59:o;12877:306::-;;12988:2;12976:9;12967:7;12963:23;12959:32;12956:2;;;13009:6;13001;12994:22;12956:2;13040:23;;-1:-1:-1;;;;;;13092:32:59;;13082:43;;13072:2;;13144:6;13136;13129:22;13582:255;;;13722:2;13710:9;13701:7;13697:23;13693:32;13690:2;;;13743:6;13735;13728:22;13690:2;-1:-1:-1;;13771:16:59;;13827:2;13812:18;;;13806:25;13771:16;;13806:25;;-1:-1:-1;13680:157:59:o;13842:477::-;;13923:5;13917:12;13950:6;13945:3;13938:19;13975:3;13987:162;14001:6;13998:1;13995:13;13987:162;;;14063:4;14119:13;;;14115:22;;14109:29;14091:11;;;14087:20;;14080:59;14016:12;13987:162;;;14167:6;14164:1;14161:13;14158:2;;;14233:3;14226:4;14217:6;14212:3;14208:16;14204:27;14197:40;14158:2;-1:-1:-1;14301:2:59;14280:15;-1:-1:-1;;14276:29:59;14267:39;;;;14308:4;14263:50;;13893:426;-1:-1:-1;;13893:426:59:o;14324:203::-;-1:-1:-1;;;;;14488:32:59;;;;14470:51;;14458:2;14443:18;;14425:102::o;14532:635::-;14703:2;14755:21;;;14825:13;;14728:18;;;14847:22;;;14532:635;;14703:2;14926:15;;;;14900:2;14885:18;;;14532:635;14972:169;14986:6;14983:1;14980:13;14972:169;;;15047:13;;15035:26;;15116:15;;;;15081:12;;;;15008:1;15001:9;14972:169;;;-1:-1:-1;15158:3:59;;14683:484;-1:-1:-1;;;;;;14683:484:59:o;15172:187::-;15337:14;;15330:22;15312:41;;15300:2;15285:18;;15267:92::o;15364:177::-;15510:25;;;15498:2;15483:18;;15465:76::o;15546:202::-;-1:-1:-1;;;;;;15708:33:59;;;;15690:52;;15678:2;15663:18;;15645:103::o;15753:219::-;;15900:2;15889:9;15882:21;15920:46;15962:2;15951:9;15947:18;15939:6;15920:46;:::i;16428:354::-;16630:2;16612:21;;;16669:2;16649:18;;;16642:30;16708:32;16703:2;16688:18;;16681:60;16773:2;16758:18;;16602:180::o;16787:404::-;16989:2;16971:21;;;17028:2;17008:18;;;17001:30;17067:34;17062:2;17047:18;;17040:62;-1:-1:-1;;;17133:2:59;17118:18;;17111:38;17181:3;17166:19;;16961:230::o;17196:353::-;17398:2;17380:21;;;17437:2;17417:18;;;17410:30;17476:31;17471:2;17456:18;;17449:59;17540:2;17525:18;;17370:179::o;17554:354::-;17756:2;17738:21;;;17795:2;17775:18;;;17768:30;17834:32;17829:2;17814:18;;17807:60;17899:2;17884:18;;17728:180::o;17913:415::-;18115:2;18097:21;;;18154:2;18134:18;;;18127:30;18193:34;18188:2;18173:18;;18166:62;-1:-1:-1;;;18259:2:59;18244:18;;18237:49;18318:3;18303:19;;18087:241::o;18333:340::-;18535:2;18517:21;;;18574:2;18554:18;;;18547:30;-1:-1:-1;;;18608:2:59;18593:18;;18586:46;18664:2;18649:18;;18507:166::o;18678:399::-;18880:2;18862:21;;;18919:2;18899:18;;;18892:30;18958:34;18953:2;18938:18;;18931:62;-1:-1:-1;;;19024:2:59;19009:18;;19002:33;19067:3;19052:19;;18852:225::o;19082:348::-;19284:2;19266:21;;;19323:2;19303:18;;;19296:30;-1:-1:-1;;;19357:2:59;19342:18;;19335:54;19421:2;19406:18;;19256:174::o;19435:403::-;19637:2;19619:21;;;19676:2;19656:18;;;19649:30;19715:34;19710:2;19695:18;;19688:62;-1:-1:-1;;;19781:2:59;19766:18;;19759:37;19828:3;19813:19;;19609:229::o;19843:334::-;20045:2;20027:21;;;20084:2;20064:18;;;20057:30;-1:-1:-1;;;20118:2:59;20103:18;;20096:40;20168:2;20153:18;;20017:160::o;20182:355::-;20384:2;20366:21;;;20423:2;20403:18;;;20396:30;20462:33;20457:2;20442:18;;20435:61;20528:2;20513:18;;20356:181::o;20724:248::-;20898:25;;;20954:2;20939:18;;20932:34;20886:2;20871:18;;20853:119::o;20977:242::-;21047:2;21041:9;21077:17;;;-1:-1:-1;;;;;21109:34:59;;21145:22;;;21106:62;21103:2;;;21171:9;21103:2;21198;21191:22;21021:198;;-1:-1:-1;21021:198:59:o;21224:183::-;;-1:-1:-1;;;;;21312:30:59;;21309:2;;;21345:9;21309:2;-1:-1:-1;21396:4:59;21377:17;;;21373:28;;21299:108::o;21412:88::-;21487:3;21483:15;;21469:31::o;21505:764::-;;21586:4;21568:16;21565:26;21562:2;;;21594:5;;21562:2;21635:1;21630:3;21625;21610:27;21697:10;21659:36;21690:3;21684:10;21659:36;:::i;:::-;21656:52;21646:2;;21712:5;;21646:2;21746;21740:9;21786:16;-1:-1:-1;;21782:29:59;21779:1;21740:9;21758:54;21835:11;;21865:16;-1:-1:-1;;;;;21933:14:59;;;21964:4;21952:17;;21949:25;-1:-1:-1;21930:45:59;21927:2;;;21978:5;;;;;;21927:2;22015:6;22009:4;22005:17;21994:28;;22051:3;22045:10;22031:24;;22078:2;22070:6;22067:14;22064:2;;;22084:5;;;;;;22064:2;;22145:16;22139:4;22135:27;22128:4;22119:6;22114:3;22110:16;22106:27;22103:60;22100:2;;;22166:5;;;;;22100:2;22231;22210:15;-1:-1:-1;;22206:29:59;22197:39;;22238:4;22193:50;22189:2;22182:62;22201:3;-1:-1:-1;;21552:717:59;:::o;22274:133::-;-1:-1:-1;;;;;22351:31:59;;22341:42;;22331:2;;22397:1;22394;22387:12;22331:2;22321:86;:::o;22412:120::-;22500:5;22493:13;22486:21;22479:5;22476:32;22466:2;;22522:1;22519;22512:12

Swarm Source

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