Contract 0xe2a9b15E283456894246499Fb912CCe717f83319 1

 

Contract Overview

Balance:
0 MATIC

MATIC Value:
$0.00

Token:
Txn Hash Method
Block
From
To
Value [Txn Fee]
0xfd41dce70d53e9adf04a53e0e782de9d41dc7028361d537d08f3e54d22884a49Set Sale Price195242262021-09-26 5:31:0612 hrs 42 mins ago0x3acc73a5e87c24cde92c69a52a9db9f5ee55294b IN  0xe2a9b15e283456894246499fb912cce717f833190 MATIC0.0000547327
0xc52c4ed266f0efdef8707bb8b487e0c06de57b96b0ac90f9d725b43ebffc6481Safe Transfer Fr...195241312021-09-26 5:27:4812 hrs 46 mins ago0x3acc73a5e87c24cde92c69a52a9db9f5ee55294b IN  0xe2a9b15e283456894246499fb912cce717f833190 MATIC0.0001132848
0x75cb8aed3af8435273e8b3e29e40dd8745cd519008c922d49fb951de00faf1eaSet Sale Price195240462021-09-26 5:24:5412 hrs 49 mins ago0x3acc73a5e87c24cde92c69a52a9db9f5ee55294b IN  0xe2a9b15e283456894246499fb912cce717f833190 MATIC0.003302635
0x381dd9531698296b87e51d186ff7b169f408d21373fbb907fdc5b1971dbfd8a1Create Proton Fo...195199282021-09-26 2:41:0115 hrs 32 mins ago0x3acc73a5e87c24cde92c69a52a9db9f5ee55294b IN  0xe2a9b15e283456894246499fb912cce717f833190 MATIC0.00291838
0xcd832b062c30a0d6e0ba5d5da37161e0da6f92ddc1ef102c4c6949c3618bb54cCreate Proton Fo...195198602021-09-26 2:38:4115 hrs 35 mins ago0x3acc73a5e87c24cde92c69a52a9db9f5ee55294b IN  0xe2a9b15e283456894246499fb912cce717f833190 MATIC0.00291838
0x7e30798cd93a56cdfef1eb19425f9b6e6a21014cc352b09928df223d7f32eb59Create Proton Fo...195186012021-09-26 1:53:1716 hrs 20 mins ago0x3acc73a5e87c24cde92c69a52a9db9f5ee55294b IN  0xe2a9b15e283456894246499fb912cce717f833190 MATIC0.00068584236
0x84d79afec4e07a8008e79aa5f54b2b261d431661a8224b41bd9cac3ad1592ec3Set Sale Price194800342021-09-25 1:52:081 day 16 hrs ago0xe0945b7d8f1c5061857201191de442e8124b56c2 IN  0xe2a9b15e283456894246499fb912cce717f833190 MATIC0.000094361
0xd06dbeef43781d83711f561ea5a7c7b0df004a61c06316de298f51f599fcbb01Create Proton Fo...194798152021-09-25 1:44:371 day 16 hrs ago0xe0945b7d8f1c5061857201191de442e8124b56c2 IN  0xe2a9b15e283456894246499fb912cce717f833190 MATIC0.000342702034
0xe4c41f08df45fae71a949cdd928188129640ba6b6d6778c776344719fe1c2e09Safe Transfer Fr...194697532021-09-24 19:22:041 day 22 hrs ago0xbeae36aefd7ae78ac1d59981bd2969d84eb5430c IN  0xe2a9b15e283456894246499fb912cce717f833190 MATIC0.000283212
0xe08c7cdc56781b55df5d7b66f407fec3a1382913679f053e5a6bb99021f33fdaSafe Transfer Fr...194697372021-09-24 19:21:321 day 22 hrs ago0xbeae36aefd7ae78ac1d59981bd2969d84eb5430c IN  0xe2a9b15e283456894246499fb912cce717f833190 MATIC0.000363912
0xc367b5a025c48abd3003673383345c637def98a88d6c0f5d35ebbcc0c04094a4Create Proton Fo...194696802021-09-24 19:19:341 day 22 hrs ago0xbeae36aefd7ae78ac1d59981bd2969d84eb5430c IN  0xe2a9b15e283456894246499fb912cce717f833190 MATIC0.001340545
0x8526d719eee352f5be950583893aed774d24fc0f1e0f3d776bb8373e358216f3Create Proton Fo...194695922021-09-24 19:16:341 day 22 hrs ago0xbeae36aefd7ae78ac1d59981bd2969d84eb5430c IN  0xe2a9b15e283456894246499fb912cce717f833190 MATIC0.001072436
0xea7219cd3193d6bb00af028f6616963bdc46974c3d8f4ab0177e0045f52f2b4cCreate Proton Fo...194592122021-09-24 13:01:572 days 5 hrs ago0x9c57027b1eca93093a6f446422c59c85a5a3fa52 IN  0xe2a9b15e283456894246499fb912cce717f833190 MATIC0.004167199508
0xf7dca1ea3699028395895d63d5c05bc36d925035d63651d87ab99436e8efc0edCreate Proton Fo...194588912021-09-24 12:50:552 days 5 hrs ago0x9c57027b1eca93093a6f446422c59c85a5a3fa52 IN  0xe2a9b15e283456894246499fb912cce717f833190 MATIC0.00145919
0x19dc0fbff353711cf45f1e5354be31543a5709739f1436721dccbf5640c659cfSet Approval For...194574362021-09-24 11:58:282 days 6 hrs ago0xfe879cc3e4089f618cf5b8bbc8edd9a6cecdb60d IN  0xe2a9b15e283456894246499fb912cce717f833190 MATIC0.00073896
0x23c1131872e344c0ce23fc6bb473b36782b6f378fbe38548887f35ba14645915Safe Transfer Fr...194245772021-09-23 15:31:183 days 2 hrs ago0x9ff07dff83f2333d96a034e2680c52f9050bd73e IN  0xe2a9b15e283456894246499fb912cce717f833190 MATIC0.000625224
0x1d8ecb3e3065cb26e918f61f42eff3edcbe1236995bea63420cba20ae80e4344Create Proton Fo...194245352021-09-23 15:29:423 days 2 hrs ago0x9ff07dff83f2333d96a034e2680c52f9050bd73e IN  0xe2a9b15e283456894246499fb912cce717f833190 MATIC0.001302408
0x62b2511d917b704eea6d5ff22c3c42ef79ee401b7439e48e7600d480b7b899e0Set Sale Price194243432021-09-23 15:20:583 days 2 hrs ago0x289314cd8d5147e32ce3f32fd030467df92d57a7 IN  0xe2a9b15e283456894246499fb912cce717f833190 MATIC0.000248725
0x650df8371c529361b97f0cea7931f4caaa5ceb2f3beb5a183a295e1aefa97776Set Sale Price194243432021-09-23 15:20:583 days 2 hrs ago0x289314cd8d5147e32ce3f32fd030467df92d57a7 IN  0xe2a9b15e283456894246499fb912cce717f833190 MATIC0.0002264664
0x18985d9aa3e9ff507c318af08ea9dc5cd18b78166a561d834d514abba1b91793Create Proton Fo...194238072021-09-23 15:00:083 days 3 hrs ago0x289314cd8d5147e32ce3f32fd030467df92d57a7 IN  0xe2a9b15e283456894246499fb912cce717f833190 MATIC0.00072283644
0xdcffb2b1adc26a75d3dbb5a813613c6e76c8ae4f5ea7b017c9615a2d48115be8Set Approval For...193879282021-09-22 15:06:224 days 3 hrs ago0xf8e8f48d0e72e41a21acc8897d4012126d04de78 IN  0xe2a9b15e283456894246499fb912cce717f833190 MATIC0.0000880594
0x48d61068493a68f232cbd78bd7bad0154ff1a68dbfdd8d4c836fca2cb8fa7797Safe Transfer Fr...193462172021-09-21 11:10:035 days 7 hrs ago0x0e41c9b548cf0545377aeeb693a6006172f1af81 IN  0xe2a9b15e283456894246499fb912cce717f833190 MATIC0.000119429334
0x59130cc681816fec1650404c2a6b5366a42e2fce37cb6e017e2eea99db03c621Create Proton Fo...193172922021-09-20 16:30:176 days 1 hr ago0x757026efa43363770df21bb71e3f25ab82c7b68b IN  0xe2a9b15e283456894246499fb912cce717f833190 MATIC0.001651685494
0x63dbc82d3e297282f306df0ab8fedbfbfb03f8d9cec3c68e0e0fea6fe187a704Set Sale Price192832462021-09-19 18:52:536 days 23 hrs ago0x30e8b1a29aaa66a669fb05afaf4b9b4206c3a6a7 IN  0xe2a9b15e283456894246499fb912cce717f833190 MATIC0.00004743869
0x5da735737251bd6886f46f9e6a2dcf75c9a90e80adbb7df5ef661799bb879483Create Proton Fo...192769452021-09-19 14:41:487 days 3 hrs ago0xc9c7ff4a5aec619d0f26cbc28049b1d173396421 IN  0xe2a9b15e283456894246499fb912cce717f833190 MATIC0.00039397842
[ Download CSV Export 
Latest 11 internal transactions
Parent Txn Hash Block From To Value
0x1a1d151f163df634b124686e9ffb947232ef87f23c20c3d705acf3b3a95f0f1a178833832021-08-11 23:52:2245 days 18 hrs ago 0xe2a9b15e283456894246499fb912cce717f833190x498141a2d2eb356251da845ba3ceda1e25d24a581 MATIC
0xb6719ffcc0af87b80feed55b1518fdf6cf5a4e3701dce2f58de7c749b04e3dd3176544242021-08-05 17:52:0152 days 21 mins ago 0xe2a9b15e283456894246499fb912cce717f833190x9f07dc77f0de3514c429d2346301b6d0ff8d46a6488 MATIC
0xea87c17eb7f96e529adc53255e64bf2c26a84c35e4df02a9ddc44599db843e61163862842021-07-02 1:47:3786 days 16 hrs ago 0xe2a9b15e283456894246499fb912cce717f833190x88bade0ce190b854aa4754fa474736d8e01dbdc3600 MATIC
0x79c7e40e0a3dd4d689f11f4ea7e343cd6897581a1f199276ab164c1086f87efe163861262021-07-02 1:42:1386 days 16 hrs ago 0xe2a9b15e283456894246499fb912cce717f833190x88bade0ce190b854aa4754fa474736d8e01dbdc3100 MATIC
0xa1995725fd26065eec10ca958c8129ed3f73a6c503af53491d7148ef43c69d70163860512021-07-02 1:38:3286 days 16 hrs ago 0xe2a9b15e283456894246499fb912cce717f833190x88bade0ce190b854aa4754fa474736d8e01dbdc3100 MATIC
0xe6eea9941c55bca1370b38a55ed7eacff89daeea9da716e4a059c3619dc097a9163838962021-07-02 0:20:0286 days 17 hrs ago 0xe2a9b15e283456894246499fb912cce717f833190x88bade0ce190b854aa4754fa474736d8e01dbdc3100 MATIC
0x5057d7539de3af068292c19c9bf07041f374c88fd53e38f265c63da9cdb8c32d162925162021-06-29 15:57:3289 days 2 hrs ago 0xe2a9b15e283456894246499fb912cce717f833190xfe85593e8dc16a256ce105175295913f79d1fed71,000 MATIC
0x06400124d778af5695817937ef085e0b486b7acfd05448458df8e1b7644b61b3162922342021-06-29 15:45:4489 days 2 hrs ago 0xe2a9b15e283456894246499fb912cce717f833190x3433c2753da24df566ea14c40584179e97396cf31,700 MATIC
0x68c38aaf5c86edd743408d7c8a1ead3ab70aad98647bc7f2a04f092b4e3930a4161341722021-06-25 13:11:0493 days 5 hrs ago 0xe2a9b15e283456894246499fb912cce717f833190x8c77319953e63b3629083b058f49a408f7cac5b30.1 MATIC
0x4dbbcf873faed0ba596786687c29b0c29b8a1bc16f5db38dbec3f1ee09cd7cbb161044002021-06-24 18:57:4693 days 23 hrs ago 0xe2a9b15e283456894246499fb912cce717f833190x8c77319953e63b3629083b058f49a408f7cac5b30.1 MATIC
0x8c9fbae964d3fefa8610b98aa9117ad56097270fb500274dddfd7141486850e9161029652021-06-24 18:06:1494 days 7 mins ago 0xe2a9b15e283456894246499fb912cce717f833190x6a1387e5fcab125579a873a4a65d5acd78d1c3460.0001 MATIC
[ Download CSV Export 
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
Proton

Compiler Version
v0.6.12+commit.27d51765

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 30 : Proton.sol
// SPDX-License-Identifier: MIT

// Proton.sol -- Part of the Charged Particles Protocol
// Copyright (c) 2021 Firma Lux, Inc. <https://charged.fi>
//
// 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 NON-INFRINGEMENT. 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.

pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;

import "../lib/ERC721.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";

import "../interfaces/IProton.sol";
import "../interfaces/IUniverse.sol";
import "../interfaces/IChargedState.sol";
import "../interfaces/IChargedSettings.sol";
import "../interfaces/IChargedParticles.sol";

import "../lib/BlackholePrevention.sol";
import "../lib/RelayRecipient.sol";


contract Proton is IProton, ERC721, Ownable, RelayRecipient, ReentrancyGuard, BlackholePrevention {
  using SafeMath for uint256;
  using Address for address payable;
  using Counters for Counters.Counter;

  uint256 constant internal PERCENTAGE_SCALE = 1e4;   // 10000  (100%)
  uint256 constant internal MAX_ROYALTIES = 8e3;      // 8000   (80%)

  IUniverse internal _universe;
  IChargedState internal _chargedState;
  IChargedSettings internal _chargedSettings;
  IChargedParticles internal _chargedParticles;

  Counters.Counter internal _tokenIds;

  mapping (uint256 => address) internal _tokenCreator;
  mapping (uint256 => uint256) internal _tokenCreatorRoyaltiesPct;
  mapping (uint256 => address) internal _tokenCreatorRoyaltiesRedirect;
  mapping (address => uint256) internal _tokenCreatorClaimableRoyalties;

  mapping (uint256 => uint256) internal _tokenSalePrice;
  mapping (uint256 => uint256) internal _tokenLastSellPrice;

  bool internal _paused;


  /***********************************|
  |          Initialization           |
  |__________________________________*/

  constructor() public ERC721("Charged Particles - Proton", "PROTON") {}


  /***********************************|
  |              Public               |
  |__________________________________*/

  function creatorOf(uint256 tokenId) external view virtual override returns (address) {
    return _tokenCreator[tokenId];
  }

  function getSalePrice(uint256 tokenId) external view virtual override returns (uint256) {
    return _tokenSalePrice[tokenId];
  }

  function getLastSellPrice(uint256 tokenId) external view virtual override returns (uint256) {
    return _tokenLastSellPrice[tokenId];
  }

  function getCreatorRoyalties(address account) external view virtual override returns (uint256) {
    return _tokenCreatorClaimableRoyalties[account];
  }

  function getCreatorRoyaltiesPct(uint256 tokenId) external view virtual override returns (uint256) {
    return _tokenCreatorRoyaltiesPct[tokenId];
  }

  function getCreatorRoyaltiesReceiver(uint256 tokenId) external view virtual override returns (address) {
    return _creatorRoyaltiesReceiver(tokenId);
  }

  function claimCreatorRoyalties()
    external
    virtual
    override
    nonReentrant
    whenNotPaused
    returns (uint256)
  {
    return _claimCreatorRoyalties(_msgSender());
  }

  function createChargedParticle(
    address creator,
    address receiver,
    address referrer,
    string memory tokenMetaUri,
    string memory walletManagerId,
    address assetToken,
    uint256 assetAmount,
    uint256 annuityPercent
  )
    external
    virtual
    override
    nonReentrant
    whenNotPaused
    returns (uint256 newTokenId)
  {
    newTokenId = _createChargedParticle(
      creator,
      receiver,
      referrer,
      tokenMetaUri,
      walletManagerId,
      assetToken,
      assetAmount,
      annuityPercent
    );
  }

  function createBasicProton(
    address creator,
    address receiver,
    string memory tokenMetaUri
  )
    external
    virtual
    override
    whenNotPaused
    returns (uint256 newTokenId)
  {
    newTokenId = _createProton(
      creator,
      receiver,
      tokenMetaUri,
      0, // annuityPercent,
      0, // royaltiesPercent
      0  // salePrice
    );
  }

  function createProton(
    address creator,
    address receiver,
    string memory tokenMetaUri,
    uint256 annuityPercent
  )
    external
    virtual
    override
    whenNotPaused
    returns (uint256 newTokenId)
  {
    newTokenId = _createProton(
      creator,
      receiver,
      tokenMetaUri,
      annuityPercent,
      0, // royaltiesPercent
      0  // salePrice
    );
  }

  function createProtonForSale(
    address creator,
    address receiver,
    string memory tokenMetaUri,
    uint256 annuityPercent,
    uint256 royaltiesPercent,
    uint256 salePrice
  )
    external
    virtual
    override
    whenNotPaused
    returns (uint256 newTokenId)
  {
    newTokenId = _createProton(
      creator,
      receiver,
      tokenMetaUri,
      annuityPercent,
      royaltiesPercent,
      salePrice
    );
  }

  function batchProtonsForSale(
    address creator,
    uint256 annuityPercent,
    uint256 royaltiesPercent,
    string[] calldata tokenMetaUris,
    uint256[] calldata salePrices
  )
    external
    virtual
    override
    whenNotPaused
  {
    _batchProtonsForSale(
      creator,
      annuityPercent,
      royaltiesPercent,
      tokenMetaUris,
      salePrices
    );
  }

  function buyProton(uint256 tokenId)
    external
    payable
    virtual
    override
    nonReentrant
    whenNotPaused
    returns (bool)
  {
    return _buyProton(tokenId);
  }

  /***********************************|
  |     Only Token Creator/Owner      |
  |__________________________________*/

  function setSalePrice(uint256 tokenId, uint256 salePrice)
    external
    virtual
    override
    whenNotPaused
    onlyTokenOwnerOrApproved(tokenId)
  {
    _setSalePrice(tokenId, salePrice);
  }

  function setRoyaltiesPct(uint256 tokenId, uint256 royaltiesPct)
    external
    virtual
    override
    whenNotPaused
    onlyTokenCreator(tokenId)
    onlyTokenOwnerOrApproved(tokenId)
  {
    _setRoyaltiesPct(tokenId, royaltiesPct);
  }

  function setCreatorRoyaltiesReceiver(uint256 tokenId, address receiver)
    external
    virtual
    override
    whenNotPaused
    onlyTokenCreator(tokenId)
  {
    _tokenCreatorRoyaltiesRedirect[tokenId] = receiver;
  }


  /***********************************|
  |          Only Admin/DAO           |
  |__________________________________*/

  function setPausedState(bool state) external virtual onlyOwner {
    _paused = state;
    emit PausedStateSet(state);
  }

  /**
    * @dev Setup the ChargedParticles Interface
    */
  function setUniverse(address universe) external virtual onlyOwner {
    _universe = IUniverse(universe);
    emit UniverseSet(universe);
  }

  /**
    * @dev Setup the ChargedParticles Interface
    */
  function setChargedParticles(address chargedParticles) external virtual onlyOwner {
    _chargedParticles = IChargedParticles(chargedParticles);
    emit ChargedParticlesSet(chargedParticles);
  }

  /// @dev Setup the Charged-State Controller
  function setChargedState(address stateController) external virtual onlyOwner {
    _chargedState = IChargedState(stateController);
    emit ChargedStateSet(stateController);
  }

  /// @dev Setup the Charged-Settings Controller
  function setChargedSettings(address settings) external virtual onlyOwner {
    _chargedSettings = IChargedSettings(settings);
    emit ChargedSettingsSet(settings);
  }

  function setTrustedForwarder(address _trustedForwarder) external virtual onlyOwner {
    trustedForwarder = _trustedForwarder;
  }

  /***********************************|
  |          Only Admin/DAO           |
  |      (blackhole prevention)       |
  |__________________________________*/

  function withdrawEther(address payable receiver, uint256 amount) external onlyOwner {
    _withdrawEther(receiver, amount);
  }

  function withdrawErc20(address payable receiver, address tokenAddress, uint256 amount) external onlyOwner {
    _withdrawERC20(receiver, tokenAddress, amount);
  }

  function withdrawERC721(address payable receiver, address tokenAddress, uint256 tokenId) external onlyOwner {
    _withdrawERC721(receiver, tokenAddress, tokenId);
  }


  /***********************************|
  |         Private Functions         |
  |__________________________________*/

  function _setSalePrice(uint256 tokenId, uint256 salePrice) internal virtual {
    // Temp-Lock/Unlock NFT
    //  prevents front-running the sale and draining the value of the NFT just before sale
    _chargedState.setTemporaryLock(address(this), tokenId, (salePrice > 0));

    _tokenSalePrice[tokenId] = salePrice;
    emit SalePriceSet(tokenId, salePrice);
  }

  function _setRoyaltiesPct(uint256 tokenId, uint256 royaltiesPct) internal virtual {
    require(royaltiesPct <= MAX_ROYALTIES, "PRT:E-421");
    _tokenCreatorRoyaltiesPct[tokenId] = royaltiesPct;
    emit CreatorRoyaltiesSet(tokenId, royaltiesPct);
  }

  function _creatorRoyaltiesReceiver(uint256 tokenId) internal view virtual returns (address) {
    address receiver = _tokenCreatorRoyaltiesRedirect[tokenId];
    if (receiver == address(0x0)) {
      receiver = _tokenCreator[tokenId];
    }
    return receiver;
  }

  function _createChargedParticle(
    address creator,
    address receiver,
    address referrer,
    string memory tokenMetaUri,
    string memory walletManagerId,
    address assetToken,
    uint256 assetAmount,
    uint256 annuityPercent
  )
    internal
    virtual
    returns (uint256 newTokenId)
  {
    require(address(_chargedParticles) != address(0x0), "PRT:E-107");

    newTokenId = _createProton(creator, receiver, tokenMetaUri, annuityPercent, 0, 0);

    _chargeParticle(newTokenId, walletManagerId, assetToken, assetAmount, referrer);
  }

  function _createProton(
    address creator,
    address receiver,
    string memory tokenMetaUri,
    uint256 annuityPercent,
    uint256 royaltiesPercent,
    uint256 salePrice
  )
    internal
    virtual
    returns (uint256 newTokenId)
  {
    _tokenIds.increment();

    newTokenId = _tokenIds.current();
    _safeMint(receiver, newTokenId, "");
    _tokenCreator[newTokenId] = creator;

    _setTokenURI(newTokenId, tokenMetaUri);

    if (royaltiesPercent > 0) {
      _setRoyaltiesPct(newTokenId, royaltiesPercent);
    }

    if (salePrice > 0) {
      _setSalePrice(newTokenId, salePrice);
    }

    if (annuityPercent > 0) {
      _chargedSettings.setCreatorAnnuities(
        address(this),
        newTokenId,
        creator,
        annuityPercent
      );
    }
  }

  function _batchProtonsForSale(
    address creator,
    uint256 annuityPercent,
    uint256 royaltiesPercent,
    string[] calldata tokenMetaUris,
    uint256[] calldata salePrices
  )
    internal
    virtual
  {
    require(tokenMetaUris.length == salePrices.length, "PRT:E-202");
    address self = address(this);

    uint256 count = tokenMetaUris.length;
    for (uint256 i = 0; i < count; i++) {
      _tokenIds.increment();
      uint256 newTokenId = _tokenIds.current();

      _safeMint(creator, newTokenId, "");
      _tokenCreator[newTokenId] = creator;

      _setTokenURI(newTokenId, tokenMetaUris[i]);

      if (royaltiesPercent > 0) {
        _setRoyaltiesPct(newTokenId, royaltiesPercent);
      }

      uint256 salePrice = salePrices[i];
      if (salePrice > 0) {
        _setSalePrice(newTokenId, salePrice);
      }

      if (annuityPercent > 0) {
        _chargedSettings.setCreatorAnnuities(
          self,
          newTokenId,
          creator,
          annuityPercent
        );
      }
    }
  }

  function _chargeParticle(
    uint256 tokenId,
    string memory walletManagerId,
    address assetToken,
    uint256 assetAmount,
    address referrer
  )
    internal
    virtual
  {
    _collectAssetToken(_msgSender(), assetToken, assetAmount);

    IERC20(assetToken).approve(address(_chargedParticles), assetAmount);

    _chargedParticles.energizeParticle(
      address(this),
      tokenId,
      walletManagerId,
      assetToken,
      assetAmount,
      referrer
    );
  }

  function _buyProton(uint256 tokenId)
    internal
    virtual
    returns (bool)
  {
    uint256 salePrice = _tokenSalePrice[tokenId];
    require(salePrice > 0, "PRT:E-416");
    require(msg.value >= salePrice, "PRT:E-414");

    uint256 ownerAmount = salePrice;
    uint256 creatorAmount;
    address oldOwner = ownerOf(tokenId);
    address newOwner = _msgSender();

    // Creator Royalties
    address royaltiesReceiver = _creatorRoyaltiesReceiver(tokenId);
    uint256 royaltiesPct = _tokenCreatorRoyaltiesPct[tokenId];
    uint256 lastSellPrice = _tokenLastSellPrice[tokenId];
    if (royaltiesPct > 0 && lastSellPrice > 0 && salePrice > lastSellPrice) {
      creatorAmount = (salePrice - lastSellPrice).mul(royaltiesPct).div(PERCENTAGE_SCALE);
      ownerAmount = ownerAmount.sub(creatorAmount);
    }
    _tokenLastSellPrice[tokenId] = salePrice;

    // Signal to Universe Controller
    if (address(_universe) != address(0)) {
      _universe.onProtonSale(address(this), tokenId, oldOwner, newOwner, salePrice, royaltiesReceiver, creatorAmount);
    }

    // Reserve Royalties for Creator
    if (creatorAmount > 0) {
      _tokenCreatorClaimableRoyalties[royaltiesReceiver] = _tokenCreatorClaimableRoyalties[royaltiesReceiver].add(creatorAmount);
    }

    // Transfer Token
    _transfer(oldOwner, newOwner, tokenId);

    // Transfer Payment
    payable(oldOwner).sendValue(ownerAmount);

    emit ProtonSold(tokenId, oldOwner, newOwner, salePrice, royaltiesReceiver, creatorAmount);

    _refundOverpayment(salePrice);
    return true;
  }

  /**
    * @dev Pays out the Creator Royalties of the calling account
    * @param receiver  The receiver of the claimable royalties
    * @return          The amount of Creator Royalties claimed
    */
  function _claimCreatorRoyalties(address receiver) internal virtual returns (uint256) {
    uint256 claimableAmount = _tokenCreatorClaimableRoyalties[receiver];
    require(claimableAmount > 0, "PRT:E-411");

    delete _tokenCreatorClaimableRoyalties[receiver];
    payable(receiver).sendValue(claimableAmount);

    emit RoyaltiesClaimed(receiver, claimableAmount);
  }

  /**
    * @dev Collects the Required Asset Token from the users wallet
    * @param from         The owner address to collect the Assets from
    * @param assetAmount  The Amount of Asset Tokens to Collect
    */
  function _collectAssetToken(address from, address assetToken, uint256 assetAmount) internal virtual {
    uint256 _userAssetBalance = IERC20(assetToken).balanceOf(from);
    require(assetAmount <= _userAssetBalance, "PRT:E-411");
    // Be sure to Approve this Contract to transfer your Asset Token
    require(IERC20(assetToken).transferFrom(from, address(this), assetAmount), "PRT:E-401");
  }

  function _refundOverpayment(uint256 threshold) internal virtual {
    uint256 overage = msg.value.sub(threshold);
    if (overage > 0) {
      payable(_msgSender()).sendValue(overage);
    }
  }

  function _transfer(address from, address to, uint256 tokenId) internal virtual override {
    _tokenSalePrice[tokenId] = 0;
    _chargedState.setTemporaryLock(address(this), tokenId, false);
    super._transfer(from, to, tokenId);
  }


  /***********************************|
  |          GSN/MetaTx Relay         |
  |__________________________________*/

  /// @dev See {BaseRelayRecipient-_msgSender}.
  function _msgSender()
    internal
    view
    virtual
    override(BaseRelayRecipient, Context)
    returns (address payable)
  {
    return BaseRelayRecipient._msgSender();
  }

  /// @dev See {BaseRelayRecipient-_msgData}.
  function _msgData()
    internal
    view
    virtual
    override(BaseRelayRecipient, Context)
    returns (bytes memory)
  {
    return BaseRelayRecipient._msgData();
  }


  /***********************************|
  |             Modifiers             |
  |__________________________________*/

  modifier whenNotPaused() {
      require(!_paused, "PRT:E-101");
      _;
  }

  modifier onlyTokenOwnerOrApproved(uint256 tokenId) {
    require(_isApprovedOrOwner(_msgSender(), tokenId), "PRT:E-105");
    _;
  }

  modifier onlyTokenCreator(uint256 tokenId) {
    require(_tokenCreator[tokenId] == _msgSender(), "PRT:E-104");
    _;
  }
}

File 2 of 30 : ERC721.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.6.0;

import "@openzeppelin/contracts/GSN/Context.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721Metadata.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
import "@openzeppelin/contracts/introspection/ERC165.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/utils/EnumerableSet.sol";
import "@openzeppelin/contracts/utils/EnumerableMap.sol";
import "@openzeppelin/contracts/utils/Strings.sol";

/**
 * @title ERC721 Non-Fungible Token Standard basic implementation
 * @dev see https://eips.ethereum.org/EIPS/eip-721
 */
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Enumerable {
    using SafeMath for uint256;
    using Address for address;
    using EnumerableSet for EnumerableSet.UintSet;
    using EnumerableMap for EnumerableMap.UintToAddressMap;
    using Strings for uint256;

    /**
     * @dev Emitted when `tokenId` token is transfered from `from` to `to`.
     */
    event TransferBatch(address indexed from, address indexed to, uint256 startTokenId, uint256 count);

    // Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`
    // which can be also obtained as `IERC721Receiver(0).onERC721Received.selector`
    bytes4 private constant _ERC721_RECEIVED = 0x150b7a02;

    // Mapping from holder address to their (enumerable) set of owned tokens
    mapping (address => EnumerableSet.UintSet) private _holderTokens;

    // Enumerable mapping from token ids to their owners
    EnumerableMap.UintToAddressMap private _tokenOwners;

    // Mapping from token ID to approved address
    mapping (uint256 => address) private _tokenApprovals;

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

    // Token name
    string private _name;

    // Token symbol
    string private _symbol;

    // Optional mapping for token URIs
    mapping(uint256 => string) private _tokenURIs;

    /*
     *     bytes4(keccak256('balanceOf(address)')) == 0x70a08231
     *     bytes4(keccak256('ownerOf(uint256)')) == 0x6352211e
     *     bytes4(keccak256('approve(address,uint256)')) == 0x095ea7b3
     *     bytes4(keccak256('getApproved(uint256)')) == 0x081812fc
     *     bytes4(keccak256('setApprovalForAll(address,bool)')) == 0xa22cb465
     *     bytes4(keccak256('isApprovedForAll(address,address)')) == 0xe985e9c5
     *     bytes4(keccak256('transferFrom(address,address,uint256)')) == 0x23b872dd
     *     bytes4(keccak256('safeTransferFrom(address,address,uint256)')) == 0x42842e0e
     *     bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) == 0xb88d4fde
     *
     *     => 0x70a08231 ^ 0x6352211e ^ 0x095ea7b3 ^ 0x081812fc ^
     *        0xa22cb465 ^ 0xe985e9c ^ 0x23b872dd ^ 0x42842e0e ^ 0xb88d4fde == 0x80ac58cd
     */
    bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd;

    /*
     *     bytes4(keccak256('name()')) == 0x06fdde03
     *     bytes4(keccak256('symbol()')) == 0x95d89b41
     *     bytes4(keccak256('tokenURI(uint256)')) == 0xc87b56dd
     *
     *     => 0x06fdde03 ^ 0x95d89b41 ^ 0xc87b56dd == 0x5b5e139f
     */
    bytes4 private constant _INTERFACE_ID_ERC721_METADATA = 0x5b5e139f;

    /*
     *     bytes4(keccak256('totalSupply()')) == 0x18160ddd
     *     bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) == 0x2f745c59
     *     bytes4(keccak256('tokenByIndex(uint256)')) == 0x4f6ccce7
     *
     *     => 0x18160ddd ^ 0x2f745c59 ^ 0x4f6ccce7 == 0x780e9d63
     */
    bytes4 private constant _INTERFACE_ID_ERC721_ENUMERABLE = 0x780e9d63;

    /**
     * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
     */
    constructor (string memory name, string memory symbol) public {
        _name = name;
        _symbol = symbol;

        // register the supported interfaces to conform to ERC721 via ERC165
        _registerInterface(_INTERFACE_ID_ERC721);
        _registerInterface(_INTERFACE_ID_ERC721_METADATA);
        _registerInterface(_INTERFACE_ID_ERC721_ENUMERABLE);
    }

    /**
     * @dev See {IERC721-balanceOf}.
     */
    function balanceOf(address owner) public view override returns (uint256) {
        require(owner != address(0), "ERC721:E-403");

        return _holderTokens[owner].length();
    }

    /**
     * @dev See {IERC721-ownerOf}.
     */
    function ownerOf(uint256 tokenId) public view override returns (address) {
        return _tokenOwners.get(tokenId, "ERC721:E-405");
    }

    /**
     * @dev See {IERC721Metadata-name}.
     */
    function name() public view override returns (string memory) {
        return _name;
    }

    /**
     * @dev See {IERC721Metadata-symbol}.
     */
    function symbol() public view override returns (string memory) {
        return _symbol;
    }

    /**
     * @dev See {IERC721Metadata-tokenURI}.
     */
    function tokenURI(uint256 tokenId) public view override returns (string memory) {
        require(_exists(tokenId), "ERC721:E-405");
        return _tokenURIs[tokenId];
    }

    /**
     * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
     */
    function tokenOfOwnerByIndex(address owner, uint256 index) public view override returns (uint256) {
        return _holderTokens[owner].at(index);
    }

    /**
     * @dev See {IERC721Enumerable-totalSupply}.
     */
    function totalSupply() public view override returns (uint256) {
        // _tokenOwners are indexed by tokenIds, so .length() returns the number of tokenIds
        return _tokenOwners.length();
    }

    /**
     * @dev See {IERC721Enumerable-tokenByIndex}.
     */
    function tokenByIndex(uint256 index) public view override returns (uint256) {
        (uint256 tokenId, ) = _tokenOwners.at(index);
        return tokenId;
    }

    /**
     * @dev See {IERC721-approve}.
     */
    function approve(address to, uint256 tokenId) public virtual override {
        address owner = ownerOf(tokenId);
        require(to != owner, "ERC721:E-111");

        require(_msgSender() == owner || isApprovedForAll(owner, _msgSender()), "ERC721:E-105");

        _approve(to, tokenId);
    }

    /**
     * @dev See {IERC721-getApproved}.
     */
    function getApproved(uint256 tokenId) public view override returns (address) {
        require(_exists(tokenId), "ERC721:E-405");

        return _tokenApprovals[tokenId];
    }

    /**
     * @dev See {IERC721-setApprovalForAll}.
     */
    function setApprovalForAll(address operator, bool approved) public virtual override {
        require(operator != _msgSender(), "ERC721:E-111");

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

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

    /**
     * @dev See {IERC721-transferFrom}.
     */
    function transferFrom(address from, address to, uint256 tokenId) public virtual override {
        //solhint-disable-next-line max-line-length
        require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721:E-105");

        _transfer(from, to, tokenId);
    }

    /**
     * @dev See {IERC721-safeTransferFrom}.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId) public virtual override {
        safeTransferFrom(from, to, tokenId, "");
    }

    /**
     * @dev See {IERC721-safeTransferFrom}.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data) public virtual override {
        require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721:E-105");
        _safeTransfer(from, to, tokenId, _data);
    }

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
     * are aware of the ERC721 protocol to prevent tokens from being forever locked.
     *
     * `_data` is additional data, it has no specified format and it is sent in call to `to`.
     *
     * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
     * implement alternative mecanisms to perform token transfer, such as signature-based.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function _safeTransfer(address from, address to, uint256 tokenId, bytes memory _data) internal virtual {
        _transfer(from, to, tokenId);
        require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721:E-402");
    }

    /**
     * @dev Returns whether `tokenId` exists.
     *
     * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
     *
     * Tokens start existing when they are minted (`_mint`),
     * and stop existing when they are burned (`_burn`).
     */
    function _exists(uint256 tokenId) internal view returns (bool) {
        return _tokenOwners.contains(tokenId);
    }

    /**
     * @dev Returns whether `spender` is allowed to manage `tokenId`.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function _isApprovedOrOwner(address spender, uint256 tokenId) internal view returns (bool) {
        require(_exists(tokenId), "ERC721:E-405");
        address owner = ownerOf(tokenId);
        return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender));
    }

    /**
     * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
     * forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
     */
    function _safeMint(address to, uint256 tokenId, bytes memory _data) internal virtual {
        _mint(to, tokenId);
        require(_checkOnERC721Received(address(0), to, tokenId, _data), "ERC721:E-402");
    }

    /**
     * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
     * forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
     */
    function _safeMintBatch(address to, uint256 startTokenId, uint256 count, bytes memory _data) internal virtual {
        _mintBatch(to, startTokenId, count);
        require(_checkOnERC721Received(address(0), to, startTokenId, _data), "ERC721:E-402");
    }

    /**
     * @dev Mints `tokenId` and transfers it to `to`.
     *
     * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
     *
     * Requirements:
     *
     * - `tokenId` must not exist.
     * - `to` cannot be the zero address.
     *
     * Emits a {Transfer} event.
     */
    function _mint(address to, uint256 tokenId) internal virtual {
        require(to != address(0), "ERC721:E-403");
        require(!_exists(tokenId), "ERC721:E-407");

        _holderTokens[to].add(tokenId);

        _tokenOwners.set(tokenId, to);

        emit Transfer(address(0), to, tokenId);
    }

    /**
     * @dev Mints `tokenId` and transfers it to `to`.
     *
     * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
     *
     * Requirements:
     *
     * - `tokenId` must not exist.
     * - `to` cannot be the zero address.
     *
     * Emits a {Transfer} event.
     */
    function _mintBatch(address to, uint256 startTokenId, uint256 count) internal virtual {
        require(to != address(0), "ERC721:E-403");
        require(!_exists(startTokenId), "ERC721:E-407");

        for (uint i = 0; i < count; i++) {
          uint256 tokenId = startTokenId.add(i);
          _holderTokens[to].add(tokenId);
          _tokenOwners.set(tokenId, to);
        }

        emit TransferBatch(address(0), to, startTokenId, count);
    }

    /**
     * @dev Transfers `tokenId` from `from` to `to`.
     *  As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     *
     * Emits a {Transfer} event.
     */
    function _transfer(address from, address to, uint256 tokenId) internal virtual {
        require(ownerOf(tokenId) == from, "ERC721:E-102");
        require(to != address(0), "ERC721:E-403");

        // Clear approvals from the previous owner
        _approve(address(0), tokenId);

        _holderTokens[from].remove(tokenId);
        _holderTokens[to].add(tokenId);

        _tokenOwners.set(tokenId, to);

        emit Transfer(from, to, tokenId);
    }

    /**
     * @dev Sets `_tokenURI` as the tokenURI of `tokenId`.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual {
        require(_exists(tokenId), "ERC721:E-405");
        _tokenURIs[tokenId] = _tokenURI;
    }

    /**
     * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
     * The call is not executed if the target address is not a contract.
     *
     * @param from address representing the previous owner of the given token ID
     * @param to target address that will receive the tokens
     * @param tokenId uint256 ID of the token to be transferred
     * @param _data bytes optional data to send along with the call
     * @return bool whether the call correctly returned the expected magic value
     */
    function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory _data)
        private returns (bool)
    {
        if (!to.isContract()) {
            return true;
        }
        bytes memory returndata = to.functionCall(abi.encodeWithSelector(
            IERC721Receiver(to).onERC721Received.selector,
            _msgSender(),
            from,
            tokenId,
            _data
        ), "ERC721:E-402");
        bytes4 retval = abi.decode(returndata, (bytes4));
        return (retval == _ERC721_RECEIVED);
    }

    function _approve(address to, uint256 tokenId) private {
        _tokenApprovals[tokenId] = to;
        emit Approval(ownerOf(tokenId), to, tokenId);
    }
}

File 3 of 30 : IERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.6.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 4 of 30 : SafeMath.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.6.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 5 of 30 : Ownable.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.6.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.
 */
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 6 of 30 : Counters.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.6.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 7 of 30 : Address.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.6.2;

/**
 * @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) {
        // According to EIP-1052, 0x0 is the value returned for not-yet created accounts
        // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
        // for accounts without code, i.e. `keccak256('')`
        bytes32 codehash;
        bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
        // solhint-disable-next-line no-inline-assembly
        assembly { codehash := extcodehash(account) }
        return (codehash != accountHash && codehash != 0x0);
    }

    /**
     * @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");
        return _functionCallWithValue(target, data, value, errorMessage);
    }

    function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
        require(isContract(target), "Address: call to non-contract");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
        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 8 of 30 : ReentrancyGuard.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.6.0;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;

    uint256 private _status;

    constructor () internal {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and make it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        // On the first call to nonReentrant, _notEntered will be true
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;

        _;

        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }
}

File 9 of 30 : IProton.sol
// SPDX-License-Identifier: MIT

// Proton.sol -- Part of the Charged Particles Protocol
// Copyright (c) 2021 Firma Lux, Inc. <https://charged.fi>
//
// 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 NON-INFRINGEMENT. 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.

pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";

import "../interfaces/IUniverse.sol";
import "../interfaces/IChargedState.sol";
import "../interfaces/IChargedSettings.sol";
import "../interfaces/IChargedParticles.sol";

import "../lib/BlackholePrevention.sol";
import "../lib/RelayRecipient.sol";


interface IProton is IERC721 {
  event UniverseSet(address indexed universe);
  event ChargedStateSet(address indexed chargedState);
  event ChargedSettingsSet(address indexed chargedSettings);
  event ChargedParticlesSet(address indexed chargedParticles);
  event PausedStateSet(bool isPaused);
  event SalePriceSet(uint256 indexed tokenId, uint256 salePrice);
  event CreatorRoyaltiesSet(uint256 indexed tokenId, uint256 royaltiesPct);
  event FeesWithdrawn(address indexed receiver, uint256 amount);
  event ProtonSold(uint256 indexed tokenId, address indexed oldOwner, address indexed newOwner, uint256 salePrice, address creator, uint256 creatorRoyalties);
  event RoyaltiesClaimed(address indexed receiver, uint256 amountClaimed);

  /***********************************|
  |              Public               |
  |__________________________________*/

  function creatorOf(uint256 tokenId) external view returns (address);
  function getSalePrice(uint256 tokenId) external view returns (uint256);
  function getLastSellPrice(uint256 tokenId) external view returns (uint256);
  function getCreatorRoyalties(address account) external view returns (uint256);
  function getCreatorRoyaltiesPct(uint256 tokenId) external view returns (uint256);
  function getCreatorRoyaltiesReceiver(uint256 tokenId) external view returns (address);

  function buyProton(uint256 tokenId) external payable returns (bool);
  function claimCreatorRoyalties() external returns (uint256);

  function createChargedParticle(
    address creator,
    address receiver,
    address referrer,
    string memory tokenMetaUri,
    string memory walletManagerId,
    address assetToken,
    uint256 assetAmount,
    uint256 annuityPercent
  ) external returns (uint256 newTokenId);

  function createBasicProton(
    address creator,
    address receiver,
    string memory tokenMetaUri
  ) external returns (uint256 newTokenId);

  function createProton(
    address creator,
    address receiver,
    string memory tokenMetaUri,
    uint256 annuityPercent
  ) external returns (uint256 newTokenId);

  function createProtonForSale(
    address creator,
    address receiver,
    string memory tokenMetaUri,
    uint256 annuityPercent,
    uint256 royaltiesPercent,
    uint256 salePrice
  ) external returns (uint256 newTokenId);

  function batchProtonsForSale(
    address creator,
    uint256 annuityPercent,
    uint256 royaltiesPercent,
    string[] calldata tokenMetaUris,
    uint256[] calldata salePrices
  ) external;

  /***********************************|
  |     Only Token Creator/Owner      |
  |__________________________________*/

  function setSalePrice(uint256 tokenId, uint256 salePrice) external;
  function setRoyaltiesPct(uint256 tokenId, uint256 royaltiesPct) external;
  function setCreatorRoyaltiesReceiver(uint256 tokenId, address receiver) external;
}

File 10 of 30 : IUniverse.sol
// SPDX-License-Identifier: MIT

// IUniverse.sol -- Part of the Charged Particles Protocol
// Copyright (c) 2021 Firma Lux, Inc. <https://charged.fi>
//
// 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 NON-INFRINGEMENT. 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.

pragma solidity >=0.6.0;

/**
 * @title Universal Controller interface
 * @dev ...
 */
interface IUniverse {

  event ChargedParticlesSet(address indexed chargedParticles);
  event PhotonSet(address indexed photonToken, uint256 maxSupply);
  event ProtonTokenSet(address indexed protonToken);
  event LeptonTokenSet(address indexed leptonToken);
  event QuarkTokenSet(address indexed quarkToken);
  event BosonTokenSet(address indexed bosonToken);
  event EsaMultiplierSet(address indexed assetToken, uint256 multiplier);
  event ElectrostaticAttraction(address indexed account, address photonSource, uint256 energy, uint256 multiplier);
  event ElectrostaticDischarge(address indexed account, address photonSource, uint256 energy);

  function onEnergize(
    address sender,
    address referrer,
    address contractAddress,
    uint256 tokenId,
    string calldata managerId,
    address assetToken,
    uint256 assetEnergy
  ) external;

  function onDischarge(
    address contractAddress,
    uint256 tokenId,
    string calldata managerId,
    address assetToken,
    uint256 creatorEnergy,
    uint256 receiverEnergy
  ) external;

  function onDischargeForCreator(
    address contractAddress,
    uint256 tokenId,
    string calldata managerId,
    address creator,
    address assetToken,
    uint256 receiverEnergy
  ) external;

  function onRelease(
    address contractAddress,
    uint256 tokenId,
    string calldata managerId,
    address assetToken,
    uint256 principalEnergy,
    uint256 creatorEnergy,
    uint256 receiverEnergy
  ) external;

  function onCovalentBond(
    address contractAddress,
    uint256 tokenId,
    string calldata managerId,
    address nftTokenAddress,
    uint256 nftTokenId
  ) external;

  function onCovalentBreak(
    address contractAddress,
    uint256 tokenId,
    string calldata managerId,
    address nftTokenAddress,
    uint256 nftTokenId
  ) external;

  function onProtonSale(
    address contractAddress,
    uint256 tokenId,
    address oldOwner,
    address newOwner,
    uint256 salePrice,
    address creator,
    uint256 creatorRoyalties
  ) external;
}

File 11 of 30 : IChargedState.sol
// SPDX-License-Identifier: MIT

// IChargedSettings.sol -- Part of the Charged Particles Protocol
// Copyright (c) 2021 Firma Lux, Inc. <https://charged.fi>
//
// 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 NON-INFRINGEMENT. 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.

pragma solidity >=0.6.0;

import "./IChargedSettings.sol";

/**
 * @notice Interface for Charged State
 */
interface IChargedState {

  /***********************************|
  |             Public API            |
  |__________________________________*/

  function getDischargeTimelockExpiry(address contractAddress, uint256 tokenId) external view returns (uint256 lockExpiry);
  function getReleaseTimelockExpiry(address contractAddress, uint256 tokenId) external view returns (uint256 lockExpiry);
  function getBreakBondTimelockExpiry(address contractAddress, uint256 tokenId) external view returns (uint256 lockExpiry);

  function isApprovedForDischarge(address contractAddress, uint256 tokenId, address operator) external view returns (bool);
  function isApprovedForRelease(address contractAddress, uint256 tokenId, address operator) external view returns (bool);
  function isApprovedForBreakBond(address contractAddress, uint256 tokenId, address operator) external view returns (bool);
  function isApprovedForTimelock(address contractAddress, uint256 tokenId, address operator) external view returns (bool);

  function isEnergizeRestricted(address contractAddress, uint256 tokenId) external view returns (bool);
  function isCovalentBondRestricted(address contractAddress, uint256 tokenId) external view returns (bool);

  function getDischargeState(address contractAddress, uint256 tokenId, address sender) external view
    returns (bool allowFromAll, bool isApproved, uint256 timelock, uint256 tempLockExpiry);
  function getReleaseState(address contractAddress, uint256 tokenId, address sender) external view
    returns (bool allowFromAll, bool isApproved, uint256 timelock, uint256 tempLockExpiry);
  function getBreakBondState(address contractAddress, uint256 tokenId, address sender) external view
    returns (bool allowFromAll, bool isApproved, uint256 timelock, uint256 tempLockExpiry);

  /***********************************|
  |      Only NFT Owner/Operator      |
  |__________________________________*/

  function setDischargeApproval(address contractAddress, uint256 tokenId, address operator) external;
  function setReleaseApproval(address contractAddress, uint256 tokenId, address operator) external;
  function setBreakBondApproval(address contractAddress, uint256 tokenId, address operator) external;
  function setTimelockApproval(address contractAddress, uint256 tokenId, address operator) external;
  function setApprovalForAll(address contractAddress, uint256 tokenId, address operator) external;

  function setPermsForRestrictCharge(address contractAddress, uint256 tokenId, bool state) external;
  function setPermsForAllowDischarge(address contractAddress, uint256 tokenId, bool state) external;
  function setPermsForAllowRelease(address contractAddress, uint256 tokenId, bool state) external;
  function setPermsForRestrictBond(address contractAddress, uint256 tokenId, bool state) external;
  function setPermsForAllowBreakBond(address contractAddress, uint256 tokenId, bool state) external;

  function setDischargeTimelock(
    address contractAddress,
    uint256 tokenId,
    uint256 unlockBlock
  ) external;

  function setReleaseTimelock(
    address contractAddress,
    uint256 tokenId,
    uint256 unlockBlock
  ) external;

  function setBreakBondTimelock(
    address contractAddress,
    uint256 tokenId,
    uint256 unlockBlock
  ) external;

  /***********************************|
  |         Only NFT Contract         |
  |__________________________________*/

  function setTemporaryLock(
    address contractAddress,
    uint256 tokenId,
    bool isLocked
  ) external;

  /***********************************|
  |          Particle Events          |
  |__________________________________*/

  event ChargedSettingsSet(address indexed settingsController);

  event DischargeApproval(address indexed contractAddress, uint256 indexed tokenId, address indexed owner, address operator);
  event ReleaseApproval(address indexed contractAddress, uint256 indexed tokenId, address indexed owner, address operator);
  event BreakBondApproval(address indexed contractAddress, uint256 indexed tokenId, address indexed owner, address operator);
  event TimelockApproval(address indexed contractAddress, uint256 indexed tokenId, address indexed owner, address operator);

  event TokenDischargeTimelock(address indexed contractAddress, uint256 indexed tokenId, address indexed operator, uint256 unlockBlock);
  event TokenReleaseTimelock(address indexed contractAddress, uint256 indexed tokenId, address indexed operator, uint256 unlockBlock);
  event TokenBreakBondTimelock(address indexed contractAddress, uint256 indexed tokenId, address indexed operator, uint256 unlockBlock);
  event TokenTempLock(address indexed contractAddress, uint256 indexed tokenId, uint256 unlockBlock);

  event PermsSetForRestrictCharge(address indexed contractAddress, uint256 indexed tokenId, bool state);
  event PermsSetForAllowDischarge(address indexed contractAddress, uint256 indexed tokenId, bool state);
  event PermsSetForAllowRelease(address indexed contractAddress, uint256 indexed tokenId, bool state);
  event PermsSetForRestrictBond(address indexed contractAddress, uint256 indexed tokenId, bool state);
  event PermsSetForAllowBreakBond(address indexed contractAddress, uint256 indexed tokenId, bool state);
}

File 12 of 30 : IChargedSettings.sol
// SPDX-License-Identifier: MIT

// IChargedSettings.sol -- Part of the Charged Particles Protocol
// Copyright (c) 2021 Firma Lux, Inc. <https://charged.fi>
//
// 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 NON-INFRINGEMENT. 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.

pragma solidity >=0.6.0;

import "./IWalletManager.sol";
import "./IBasketManager.sol";

/**
 * @notice Interface for Charged Settings
 */
interface IChargedSettings {

  /***********************************|
  |             Public API            |
  |__________________________________*/

  function isContractOwner(address contractAddress, address account) external view returns (bool);
  function getCreatorAnnuities(address contractAddress, uint256 tokenId) external view returns (address creator, uint256 annuityPct);
  function getCreatorAnnuitiesRedirect(address contractAddress, uint256 tokenId) external view returns (address);
  function getTempLockExpiryBlocks() external view returns (uint256);
  function getTimelockApprovals(address operator) external view returns (bool timelockAny, bool timelockOwn);
  function getAssetRequirements(address contractAddress, address assetToken) external view
    returns (string memory requiredWalletManager, bool energizeEnabled, bool restrictedAssets, bool validAsset, uint256 depositCap, uint256 depositMin, uint256 depositMax);
  function getNftAssetRequirements(address contractAddress, address nftTokenAddress) external view
    returns (string memory requiredBasketManager, bool basketEnabled, uint256 maxNfts);

  // ERC20
  function isWalletManagerEnabled(string calldata walletManagerId) external view returns (bool);
  function getWalletManager(string calldata walletManagerId) external view returns (IWalletManager);

  // ERC721
  function isNftBasketEnabled(string calldata basketId) external view returns (bool);
  function getBasketManager(string calldata basketId) external view returns (IBasketManager);

  /***********************************|
  |         Only NFT Creator          |
  |__________________________________*/

  function setCreatorAnnuities(address contractAddress, uint256 tokenId, address creator, uint256 annuityPercent) external;
  function setCreatorAnnuitiesRedirect(address contractAddress, uint256 tokenId, address creator, address receiver) external;


  /***********************************|
  |      Only NFT Contract Owner      |
  |__________________________________*/

  function setRequiredWalletManager(address contractAddress, string calldata walletManager) external;
  function setRequiredBasketManager(address contractAddress, string calldata basketManager) external;
  function setAssetTokenRestrictions(address contractAddress, bool restrictionsEnabled) external;
  function setAllowedAssetToken(address contractAddress, address assetToken, bool isAllowed) external;
  function setAssetTokenLimits(address contractAddress, address assetToken, uint256 depositMin, uint256 depositMax) external;
  function setMaxNfts(address contractAddress, address nftTokenAddress, uint256 maxNfts) external;

  /***********************************|
  |          Only Admin/DAO           |
  |__________________________________*/

  function enableNftContracts(address[] calldata contracts) external;
  function setPermsForCharge(address contractAddress, bool state) external;
  function setPermsForBasket(address contractAddress, bool state) external;
  function setPermsForTimelockAny(address contractAddress, bool state) external;
  function setPermsForTimelockSelf(address contractAddress, bool state) external;

  /***********************************|
  |          Particle Events          |
  |__________________________________*/

  event DepositCapSet(address assetToken, uint256 depositCap);
  event TempLockExpirySet(uint256 expiryBlocks);

  event WalletManagerRegistered(string indexed walletManagerId, address indexed walletManager);
  event BasketManagerRegistered(string indexed basketId, address indexed basketManager);

  event RequiredWalletManagerSet(address indexed contractAddress, string walletManager);
  event RequiredBasketManagerSet(address indexed contractAddress, string basketManager);
  event AssetTokenRestrictionsSet(address indexed contractAddress, bool restrictionsEnabled);
  event AllowedAssetTokenSet(address indexed contractAddress, address assetToken, bool isAllowed);
  event AssetTokenLimitsSet(address indexed contractAddress, address assetToken, uint256 assetDepositMin, uint256 assetDepositMax);
  event MaxNftsSet(address indexed contractAddress, address indexed nftTokenAddress, uint256 maxNfts);

  event TokenCreatorConfigsSet(address indexed contractAddress, uint256 indexed tokenId, address indexed creatorAddress, uint256 annuityPercent);
  event TokenCreatorAnnuitiesRedirected(address indexed contractAddress, uint256 indexed tokenId, address indexed redirectAddress);

  event PermsSetForCharge(address indexed contractAddress, bool state);
  event PermsSetForBasket(address indexed contractAddress, bool state);
  event PermsSetForTimelockAny(address indexed contractAddress, bool state);
  event PermsSetForTimelockSelf(address indexed contractAddress, bool state);
}

File 13 of 30 : IChargedParticles.sol
// SPDX-License-Identifier: MIT

// IChargedParticles.sol -- Part of the Charged Particles Protocol
// Copyright (c) 2021 Firma Lux, Inc. <https://charged.fi>
//
// 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 NON-INFRINGEMENT. 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.

pragma solidity >=0.6.0;

/**
 * @notice Interface for Charged Particles
 */
interface IChargedParticles {

  /***********************************|
  |             Public API            |
  |__________________________________*/

  function getStateAddress() external view returns (address stateAddress);
  function getSettingsAddress() external view returns (address settingsAddress);

  function getFeesForDeposit(uint256 assetAmount) external view returns (uint256 protocolFee);
  function baseParticleMass(address contractAddress, uint256 tokenId, string calldata walletManagerId, address assetToken) external returns (uint256);
  function currentParticleCharge(address contractAddress, uint256 tokenId, string calldata walletManagerId, address assetToken) external returns (uint256);
  function currentParticleKinetics(address contractAddress, uint256 tokenId, string calldata walletManagerId, address assetToken) external returns (uint256);
  function currentParticleCovalentBonds(address contractAddress, uint256 tokenId, string calldata basketManagerId) external view returns (uint256);

  /***********************************|
  |        Particle Mechanics         |
  |__________________________________*/

  function energizeParticle(
      address contractAddress,
      uint256 tokenId,
      string calldata walletManagerId,
      address assetToken,
      uint256 assetAmount,
      address referrer
  ) external returns (uint256 yieldTokensAmount);

  function dischargeParticle(
      address receiver,
      address contractAddress,
      uint256 tokenId,
      string calldata walletManagerId,
      address assetToken
  ) external returns (uint256 creatorAmount, uint256 receiverAmount);

  function dischargeParticleAmount(
      address receiver,
      address contractAddress,
      uint256 tokenId,
      string calldata walletManagerId,
      address assetToken,
      uint256 assetAmount
  ) external returns (uint256 creatorAmount, uint256 receiverAmount);

  function dischargeParticleForCreator(
      address receiver,
      address contractAddress,
      uint256 tokenId,
      string calldata walletManagerId,
      address assetToken,
      uint256 assetAmount
  ) external returns (uint256 receiverAmount);

  function releaseParticle(
      address receiver,
      address contractAddress,
      uint256 tokenId,
      string calldata walletManagerId,
      address assetToken
  ) external returns (uint256 creatorAmount, uint256 receiverAmount);

  function releaseParticleAmount(
    address receiver,
    address contractAddress,
    uint256 tokenId,
    string calldata walletManagerId,
    address assetToken,
    uint256 assetAmount
  ) external returns (uint256 creatorAmount, uint256 receiverAmount);

  function covalentBond(
    address contractAddress,
    uint256 tokenId,
    string calldata basketManagerId,
    address nftTokenAddress,
    uint256 nftTokenId
  ) external returns (bool success);

  function breakCovalentBond(
    address receiver,
    address contractAddress,
    uint256 tokenId,
    string calldata basketManagerId,
    address nftTokenAddress,
    uint256 nftTokenId
  ) external returns (bool success);

  /***********************************|
  |          Particle Events          |
  |__________________________________*/

  event UniverseSet(address indexed universeAddress);
  event ChargedStateSet(address indexed chargedState);
  event ChargedSettingsSet(address indexed chargedSettings);
  event LeptonTokenSet(address indexed leptonToken);
  // event DepositFeeSet(uint256 depositFeeLimit, uint256 depositFee);
  event DepositFeeSet(uint256 depositFee);
  event ProtocolFeesCollected(address indexed assetToken, uint256 depositAmount, uint256 feesCollected);
}

File 14 of 30 : BlackholePrevention.sol
// SPDX-License-Identifier: MIT

// BlackholePrevention.sol -- Part of the Charged Particles Protocol
// Copyright (c) 2021 Firma Lux, Inc. <https://charged.fi>
//
// 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 NON-INFRINGEMENT. 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.

pragma solidity >=0.6.0;

import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";

/**
 * @notice Prevents ETH or Tokens from getting stuck in a contract by allowing
 *  the Owner/DAO to pull them out on behalf of a user
 * This is only meant to contracts that are not expected to hold tokens, but do handle transferring them.
 */
contract BlackholePrevention {
  using Address for address payable;
  using SafeERC20 for IERC20;

  event WithdrawStuckEther(address indexed receiver, uint256 amount);
  event WithdrawStuckERC20(address indexed receiver, address indexed tokenAddress, uint256 amount);
  event WithdrawStuckERC721(address indexed receiver, address indexed tokenAddress, uint256 indexed tokenId);

  function _withdrawEther(address payable receiver, uint256 amount) internal virtual {
    require(receiver != address(0x0), "BHP:E-403");
    if (address(this).balance >= amount) {
      receiver.sendValue(amount);
      emit WithdrawStuckEther(receiver, amount);
    }
  }

  function _withdrawERC20(address payable receiver, address tokenAddress, uint256 amount) internal virtual {
    require(receiver != address(0x0), "BHP:E-403");
    if (IERC20(tokenAddress).balanceOf(address(this)) >= amount) {
      IERC20(tokenAddress).safeTransfer(receiver, amount);
      emit WithdrawStuckERC20(receiver, tokenAddress, amount);
    }
  }

  function _withdrawERC721(address payable receiver, address tokenAddress, uint256 tokenId) internal virtual {
    require(receiver != address(0x0), "BHP:E-403");
    if (IERC721(tokenAddress).ownerOf(tokenId) == address(this)) {
      IERC721(tokenAddress).transferFrom(address(this), receiver, tokenId);
      emit WithdrawStuckERC721(receiver, tokenAddress, tokenId);
    }
  }
}

File 15 of 30 : RelayRecipient.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0;

import "@opengsn/gsn/contracts/BaseRelayRecipient.sol";

contract RelayRecipient is BaseRelayRecipient {
  function versionRecipient() external override view returns (string memory) {
    return "1.0.0-beta.1/charged-particles.relay.recipient";
  }
}

File 16 of 30 : Context.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.6.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 17 of 30 : IERC721.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.6.2;

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

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

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

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

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

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

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

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

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

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

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

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

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

File 18 of 30 : IERC721Metadata.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.6.2;

import "./IERC721.sol";

/**
 * @title ERC-721 Non-Fungible Token Standard, optional metadata extension
 * @dev See https://eips.ethereum.org/EIPS/eip-721
 */
interface IERC721Metadata is IERC721 {

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

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

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

File 19 of 30 : IERC721Enumerable.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.6.2;

import "./IERC721.sol";

/**
 * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
 * @dev See https://eips.ethereum.org/EIPS/eip-721
 */
interface IERC721Enumerable is IERC721 {

    /**
     * @dev Returns the total amount of tokens stored by the contract.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns a token ID owned by `owner` at a given `index` of its token list.
     * Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
     */
    function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId);

    /**
     * @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
     * Use along with {totalSupply} to enumerate all tokens.
     */
    function tokenByIndex(uint256 index) external view returns (uint256);
}

File 20 of 30 : IERC721Receiver.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.6.0;

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

File 21 of 30 : ERC165.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.6.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.
 */
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 22 of 30 : EnumerableSet.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.6.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.0.0, only sets of type `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];
    }

    // 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 23 of 30 : EnumerableMap.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.6.0;

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

    // UintToAddressMap

    struct UintToAddressMap {
        Map _inner;
    }

    /**
     * @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(UintToAddressMap storage map, uint256 key, address value) internal returns (bool) {
        return _set(map._inner, bytes32(key), bytes32(uint256(value)));
    }

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

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

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

   /**
    * @dev Returns the element 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(UintToAddressMap storage map, uint256 index) internal view returns (uint256, address) {
        (bytes32 key, bytes32 value) = _at(map._inner, index);
        return (uint256(key), address(uint256(value)));
    }

    /**
     * @dev Returns the value associated with `key`.  O(1).
     *
     * Requirements:
     *
     * - `key` must be in the map.
     */
    function get(UintToAddressMap storage map, uint256 key) internal view returns (address) {
        return address(uint256(_get(map._inner, bytes32(key))));
    }

    /**
     * @dev Same as {get}, with a custom error message when `key` is not in the map.
     */
    function get(UintToAddressMap storage map, uint256 key, string memory errorMessage) internal view returns (address) {
        return address(uint256(_get(map._inner, bytes32(key), errorMessage)));
    }
}

File 24 of 30 : Strings.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.6.0;

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

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

File 25 of 30 : IERC165.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.6.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 26 of 30 : IWalletManager.sol
// SPDX-License-Identifier: MIT

// IWalletManager.sol -- Part of the Charged Particles Protocol
// Copyright (c) 2021 Firma Lux, Inc. <https://charged.fi>
//
// 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 NON-INFRINGEMENT. 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.

pragma solidity >=0.6.0;

/**
 * @title Particle Wallet Manager interface
 * @dev The wallet-manager for underlying assets attached to Charged Particles
 * @dev Manages the link between NFTs and their respective Smart-Wallets
 */
interface IWalletManager {

  event ControllerSet(address indexed controller);
  event PausedStateSet(bool isPaused);
  event NewSmartWallet(address indexed contractAddress, uint256 indexed tokenId, address indexed smartWallet, address creator, uint256 annuityPct);
  event WalletEnergized(address indexed contractAddress, uint256 indexed tokenId, address indexed assetToken, uint256 assetAmount, uint256 yieldTokensAmount);
  event WalletDischarged(address indexed contractAddress, uint256 indexed tokenId, address indexed assetToken, uint256 creatorAmount, uint256 receiverAmount);
  event WalletDischargedForCreator(address indexed contractAddress, uint256 indexed tokenId, address indexed assetToken, address creator, uint256 receiverAmount);
  event WalletReleased(address indexed contractAddress, uint256 indexed tokenId, address indexed receiver, address assetToken, uint256 principalAmount, uint256 creatorAmount, uint256 receiverAmount);
  event WalletRewarded(address indexed contractAddress, uint256 indexed tokenId, address indexed receiver, address rewardsToken, uint256 rewardsAmount);

  function isPaused() external view returns (bool);

  function isReserveActive(address contractAddress, uint256 tokenId, address assetToken) external view returns (bool);
  function getReserveInterestToken(address contractAddress, uint256 tokenId, address assetToken) external view returns (address);

  function getTotal(address contractAddress, uint256 tokenId, address assetToken) external returns (uint256);
  function getPrincipal(address contractAddress, uint256 tokenId, address assetToken) external returns (uint256);
  function getInterest(address contractAddress, uint256 tokenId, address assetToken) external returns (uint256 creatorInterest, uint256 ownerInterest);
  function getRewards(address contractAddress, uint256 tokenId, address rewardToken) external returns (uint256);

  function energize(address contractAddress, uint256 tokenId, address assetToken, uint256 assetAmount) external returns (uint256 yieldTokensAmount);
  function discharge(address receiver, address contractAddress, uint256 tokenId, address assetToken, address creatorRedirect) external returns (uint256 creatorAmount, uint256 receiverAmount);
  function dischargeAmount(address receiver, address contractAddress, uint256 tokenId, address assetToken, uint256 assetAmount, address creatorRedirect) external returns (uint256 creatorAmount, uint256 receiverAmount);
  function dischargeAmountForCreator(address receiver, address contractAddress, uint256 tokenId, address creator, address assetToken, uint256 assetAmount) external returns (uint256 receiverAmount);
  function release(address receiver, address contractAddress, uint256 tokenId, address assetToken, address creatorRedirect) external returns (uint256 principalAmount, uint256 creatorAmount, uint256 receiverAmount);
  function releaseAmount(address receiver, address contractAddress, uint256 tokenId, address assetToken, uint256 assetAmount, address creatorRedirect) external returns (uint256 principalAmount, uint256 creatorAmount, uint256 receiverAmount);
  function withdrawRewards(address receiver, address contractAddress, uint256 tokenId, address rewardsToken, uint256 rewardsAmount) external returns (uint256 amount);
  function executeForAccount(address contractAddress, uint256 tokenId, address externalAddress, uint256 ethValue, bytes memory encodedParams) external returns (bytes memory);
  function getWalletAddressById(address contractAddress, uint256 tokenId, address creator, uint256 annuityPct) external returns (address);

  function withdrawEther(address contractAddress, uint256 tokenId, address payable receiver, uint256 amount) external;
  function withdrawERC20(address contractAddress, uint256 tokenId, address payable receiver, address tokenAddress, uint256 amount) external;
  function withdrawERC721(address contractAddress, uint256 tokenId, address payable receiver, address nftTokenAddress, uint256 nftTokenId) external;
}

File 27 of 30 : IBasketManager.sol
// SPDX-License-Identifier: MIT

// IBasketManager.sol -- Part of the Charged Particles Protocol
// Copyright (c) 2021 Firma Lux, Inc. <https://charged.fi>
//
// 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 NON-INFRINGEMENT. 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.

pragma solidity >=0.6.0;

/**
 * @title Particle Basket Manager interface
 * @dev The basket-manager for underlying assets attached to Charged Particles
 * @dev Manages the link between NFTs and their respective Smart-Baskets
 */
interface IBasketManager {

  event ControllerSet(address indexed controller);
  event PausedStateSet(bool isPaused);
  event NewSmartBasket(address indexed contractAddress, uint256 indexed tokenId, address indexed smartBasket);
  event BasketAdd(address indexed contractAddress, uint256 indexed tokenId, address basketTokenAddress, uint256 basketTokenId);
  event BasketRemove(address indexed receiver, address indexed contractAddress, uint256 indexed tokenId, address basketTokenAddress, uint256 basketTokenId);

  function isPaused() external view returns (bool);

  function getTokenTotalCount(address contractAddress, uint256 tokenId) external view returns (uint256);
  function getTokenCountByType(address contractAddress, uint256 tokenId, address basketTokenAddress, uint256 basketTokenId) external returns (uint256);

  function addToBasket(address contractAddress, uint256 tokenId, address basketTokenAddress, uint256 basketTokenId) external returns (bool);
  function removeFromBasket(address receiver, address contractAddress, uint256 tokenId, address basketTokenAddress, uint256 basketTokenId) external returns (bool);
  function executeForAccount(address contractAddress, uint256 tokenId, address externalAddress, uint256 ethValue, bytes memory encodedParams) external returns (bytes memory);
  function getBasketAddressById(address contractAddress, uint256 tokenId) external returns (address);

  function withdrawEther(address contractAddress, uint256 tokenId, address payable receiver, uint256 amount) external;
  function withdrawERC20(address contractAddress, uint256 tokenId, address payable receiver, address tokenAddress, uint256 amount) external;
  function withdrawERC721(address contractAddress, uint256 tokenId, address payable receiver, address nftTokenAddress, uint256 nftTokenId) external;
}

File 28 of 30 : SafeERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.6.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 29 of 30 : BaseRelayRecipient.sol
// SPDX-License-Identifier:MIT
// solhint-disable no-inline-assembly
pragma solidity ^0.6.2;

import "./interfaces/IRelayRecipient.sol";

/**
 * A base contract to be inherited by any contract that want to receive relayed transactions
 * A subclass must use "_msgSender()" instead of "msg.sender"
 */
abstract contract BaseRelayRecipient is IRelayRecipient {

    /*
     * Forwarder singleton we accept calls from
     */
    address public trustedForwarder;

    function isTrustedForwarder(address forwarder) public override view returns(bool) {
        return forwarder == trustedForwarder;
    }

    /**
     * return the sender of this call.
     * if the call came through our trusted forwarder, return the original sender.
     * otherwise, return `msg.sender`.
     * should be used in the contract anywhere instead of msg.sender
     */
    function _msgSender() internal override virtual view returns (address payable ret) {
        if (msg.data.length >= 24 && isTrustedForwarder(msg.sender)) {
            // At this point we know that the sender is a trusted forwarder,
            // so we trust that the last bytes of msg.data are the verified sender address.
            // extract sender address from the end of msg.data
            assembly {
                ret := shr(96,calldataload(sub(calldatasize(),20)))
            }
        } else {
            return msg.sender;
        }
    }

    /**
     * return the msg.data of this call.
     * if the call came through our trusted forwarder, then the real sender was appended as the last 20 bytes
     * of the msg.data - so this method will strip those 20 bytes off.
     * otherwise, return `msg.data`
     * should be used in the contract instead of msg.data, where the difference matters (e.g. when explicitly
     * signing or hashing the
     */
    function _msgData() internal override virtual view returns (bytes memory ret) {
        if (msg.data.length >= 24 && isTrustedForwarder(msg.sender)) {
            // At this point we know that the sender is a trusted forwarder,
            // we copy the msg.data , except the last 20 bytes (and update the total length)
            assembly {
                let ptr := mload(0x40)
                // copy only size-20 bytes
                let size := sub(calldatasize(),20)
                // structure RLP data as <offset> <length> <bytes>
                mstore(ptr, 0x20)
                mstore(add(ptr,32), size)
                calldatacopy(add(ptr,64), 0, size)
                return(ptr, add(size,64))
            }
        } else {
            return msg.data;
        }
    }
}

File 30 of 30 : IRelayRecipient.sol
// SPDX-License-Identifier:MIT
pragma solidity ^0.6.2;

/**
 * a contract must implement this interface in order to support relayed transaction.
 * It is better to inherit the BaseRelayRecipient as its implementation.
 */
abstract contract IRelayRecipient {

    /**
     * return if the forwarder is trusted to forward relayed transactions to us.
     * the forwarder is required to verify the sender's signature, and verify
     * the call is not a replay.
     */
    function isTrustedForwarder(address forwarder) public virtual view returns(bool);

    /**
     * return the sender of this call.
     * if the call came through our trusted forwarder, then the real sender is appended as the last 20 bytes
     * of the msg.data.
     * otherwise, return `msg.sender`
     * should be used in the contract anywhere instead of msg.sender
     */
    function _msgSender() internal virtual view returns (address payable);

    /**
     * return the msg.data of this call.
     * if the call came through our trusted forwarder, then the real sender was appended as the last 20 bytes
     * of the msg.data - so this method will strip those 20 bytes off.
     * otherwise, return `msg.data`
     * should be used in the contract instead of msg.data, where the difference matters (e.g. when explicitly
     * signing or hashing the
     */
    function _msgData() internal virtual view returns (bytes memory);

    function versionRecipient() external virtual view returns (string memory);
}

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

Contract Security Audit

Contract ABI

[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"approved","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","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":true,"internalType":"address","name":"chargedParticles","type":"address"}],"name":"ChargedParticlesSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"chargedSettings","type":"address"}],"name":"ChargedSettingsSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"chargedState","type":"address"}],"name":"ChargedStateSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"royaltiesPct","type":"uint256"}],"name":"CreatorRoyaltiesSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"FeesWithdrawn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"isPaused","type":"bool"}],"name":"PausedStateSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":true,"internalType":"address","name":"oldOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"},{"indexed":false,"internalType":"uint256","name":"salePrice","type":"uint256"},{"indexed":false,"internalType":"address","name":"creator","type":"address"},{"indexed":false,"internalType":"uint256","name":"creatorRoyalties","type":"uint256"}],"name":"ProtonSold","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"amountClaimed","type":"uint256"}],"name":"RoyaltiesClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"salePrice","type":"uint256"}],"name":"SalePriceSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"startTokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"count","type":"uint256"}],"name":"TransferBatch","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"universe","type":"address"}],"name":"UniverseSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":true,"internalType":"address","name":"tokenAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"WithdrawStuckERC20","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":true,"internalType":"address","name":"tokenAddress","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"WithdrawStuckERC721","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"WithdrawStuckEther","type":"event"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"creator","type":"address"},{"internalType":"uint256","name":"annuityPercent","type":"uint256"},{"internalType":"uint256","name":"royaltiesPercent","type":"uint256"},{"internalType":"string[]","name":"tokenMetaUris","type":"string[]"},{"internalType":"uint256[]","name":"salePrices","type":"uint256[]"}],"name":"batchProtonsForSale","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"buyProton","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"claimCreatorRoyalties","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"creator","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"string","name":"tokenMetaUri","type":"string"}],"name":"createBasicProton","outputs":[{"internalType":"uint256","name":"newTokenId","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"creator","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"referrer","type":"address"},{"internalType":"string","name":"tokenMetaUri","type":"string"},{"internalType":"string","name":"walletManagerId","type":"string"},{"internalType":"address","name":"assetToken","type":"address"},{"internalType":"uint256","name":"assetAmount","type":"uint256"},{"internalType":"uint256","name":"annuityPercent","type":"uint256"}],"name":"createChargedParticle","outputs":[{"internalType":"uint256","name":"newTokenId","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"creator","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"string","name":"tokenMetaUri","type":"string"},{"internalType":"uint256","name":"annuityPercent","type":"uint256"}],"name":"createProton","outputs":[{"internalType":"uint256","name":"newTokenId","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"creator","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"string","name":"tokenMetaUri","type":"string"},{"internalType":"uint256","name":"annuityPercent","type":"uint256"},{"internalType":"uint256","name":"royaltiesPercent","type":"uint256"},{"internalType":"uint256","name":"salePrice","type":"uint256"}],"name":"createProtonForSale","outputs":[{"internalType":"uint256","name":"newTokenId","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"creatorOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"getCreatorRoyalties","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getCreatorRoyaltiesPct","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getCreatorRoyaltiesReceiver","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getLastSellPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getSalePrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"forwarder","type":"address"}],"name":"isTrustedForwarder","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","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":"tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","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":"address","name":"chargedParticles","type":"address"}],"name":"setChargedParticles","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"settings","type":"address"}],"name":"setChargedSettings","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"stateController","type":"address"}],"name":"setChargedState","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"setCreatorRoyaltiesReceiver","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"state","type":"bool"}],"name":"setPausedState","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"royaltiesPct","type":"uint256"}],"name":"setRoyaltiesPct","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"salePrice","type":"uint256"}],"name":"setSalePrice","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_trustedForwarder","type":"address"}],"name":"setTrustedForwarder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"universe","type":"address"}],"name":"setUniverse","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":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"tokenByIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"tokenOfOwnerByIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"trustedForwarder","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"versionRecipient","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address payable","name":"receiver","type":"address"},{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"withdrawERC721","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"receiver","type":"address"},{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawErc20","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"receiver","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawEther","outputs":[],"stateMutability":"nonpayable","type":"function"}]

60806040523480156200001157600080fd5b50604080518082018252601a81527f43686172676564205061727469636c6573202d2050726f746f6e00000000000060208083019190915282518084019093526006835265282927aa27a760d11b9083015290620000766301ffc9a760e01b62000140565b81516200008b90600690602085019062000204565b508051620000a190600790602084019062000204565b50620000b46380ac58cd60e01b62000140565b620000c6635b5e139f60e01b62000140565b620000d863780e9d6360e01b62000140565b5060009050620000e76200019b565b600980546001600160a01b0319166001600160a01b038316908117909155604051919250906000907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908290a3506001600b55620002d7565b6001600160e01b03198082161415620001765760405162461bcd60e51b81526004016200016d90620002a0565b60405180910390fd5b6001600160e01b0319166000908152602081905260409020805460ff19166001179055565b6000620001b2620001b860201b620016ac1760201c565b90505b90565b600060183610801590620001d25750620001d233620001f0565b15620001e8575060131936013560601c620001b5565b5033620001b5565b600a546001600160a01b0390811691161490565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106200024757805160ff191683800117855562000277565b8280016001018555821562000277579182015b82811115620002775782518255916020019190600101906200025a565b506200028592915062000289565b5090565b5b808211156200028557600081556001016200028a565b6020808252601c908201527f4552433136353a20696e76616c696420696e7465726661636520696400000000604082015260600190565b613e1280620002e76000396000f3fe6080604052600436106102875760003560e01c80636e5559fd1161015a578063ad82c42c116100c1578063c95d09981161007a578063c95d099814610786578063da742228146107a6578063db9f60ff146107c6578063e985e9c5146107e6578063f2fde38b14610806578063f8eb5fc51461082657610287565b8063ad82c42c146106c6578063ae9704cd146106e6578063b7683e9314610706578063b88d4fde14610726578063c87b56dd14610746578063c8c680d51461076657610287565b806382e9870f1161011357806382e9870f14610629578063846ec08c1461063c5780638da5cb5b1461065c5780639390afc71461067157806395d89b4114610691578063a22cb465146106a657610287565b80636e5559fd1461057f5780636ed6237e1461059f57806370a08231146105bf578063715018a6146105df57806371e715f4146105f45780637da0a8771461061457610287565b80632f745c59116101fe578063522f6815116101b7578063522f6815146104ca578063572b6c05146104ea578063589a17431461050a57806362c517491461052a5780636348af341461054a5780636352211e1461055f57610287565b80632f745c59146104155780632fc77797146104355780634025feb21461045557806342842e0e14610475578063486ff0cd146104955780634f6ccce7146104aa57610287565b8063095ea7b311610250578063095ea7b3146103605780631593dee11461038057806318160ddd146103a057806323b872dd146103b5578063250b2c80146103d55780632c0cd5a3146103f557610287565b8062e4eb991461028c57806301ffc9a7146102c2578063053992c5146102ef57806306fdde0314610311578063081812fc14610333575b600080fd5b34801561029857600080fd5b506102ac6102a73660046132c5565b610846565b6040516102b99190613cd9565b60405180910390f35b3480156102ce57600080fd5b506102e26102dd36600461351f565b61088d565b6040516102b9919061376d565b3480156102fb57600080fd5b5061030f61030a3660046135ab565b6108ac565b005b34801561031d57600080fd5b5061032661090c565b6040516102b99190613778565b34801561033f57600080fd5b5061035361034e366004613557565b6109a3565b6040516102b99190613614565b34801561036c57600080fd5b5061030f61037b366004613143565b6109e6565b34801561038c57600080fd5b5061030f61039b366004613103565b610a79565b3480156103ac57600080fd5b506102ac610ab9565b3480156103c157600080fd5b5061030f6103d03660046133a9565b610aca565b3480156103e157600080fd5b506102ac6103f0366004613557565b610afc565b34801561040157600080fd5b506102ac610410366004613265565b610b0e565b34801561042157600080fd5b506102ac610430366004613143565b610b4c565b34801561044157600080fd5b5061030f610450366004613587565b610b77565b34801561046157600080fd5b5061030f610470366004613103565b610c0b565b34801561048157600080fd5b5061030f6104903660046133a9565b610c4b565b3480156104a157600080fd5b50610326610c66565b3480156104b657600080fd5b506102ac6104c5366004613557565b610c86565b3480156104d657600080fd5b5061030f6104e5366004613143565b610c9c565b3480156104f657600080fd5b506102e26105053660046130cb565b610cdf565b34801561051657600080fd5b50610353610525366004613557565b610cf3565b34801561053657600080fd5b506102ac6105453660046131a6565b610d0e565b34801561055657600080fd5b506102ac610d7d565b34801561056b57600080fd5b5061035361057a366004613557565b610de4565b34801561058b57600080fd5b5061030f61059a3660046130cb565b610e20565b3480156105ab57600080fd5b5061030f6105ba366004613454565b610e9f565b3480156105cb57600080fd5b506102ac6105da3660046130cb565b610eda565b3480156105eb57600080fd5b5061030f610f23565b34801561060057600080fd5b5061035361060f366004613557565b610fa2565b34801561062057600080fd5b50610353610fad565b6102e2610637366004613557565b610fbc565b34801561064857600080fd5b506102ac6106573660046130cb565b61101d565b34801561066857600080fd5b50610353611038565b34801561067d57600080fd5b506102ac61068c36600461332d565b611047565b34801561069d57600080fd5b50610326611086565b3480156106b257600080fd5b5061030f6106c1366004613427565b6110e7565b3480156106d257600080fd5b506102ac6106e1366004613557565b6111b5565b3480156106f257600080fd5b5061030f6107013660046130cb565b6111c7565b34801561071257600080fd5b5061030f6107213660046130cb565b611246565b34801561073257600080fd5b5061030f6107413660046133bd565b6112c5565b34801561075257600080fd5b50610326610761366004613557565b611304565b34801561077257600080fd5b5061030f6107813660046135ab565b6113ca565b34801561079257600080fd5b5061030f6107a13660046130cb565b611461565b3480156107b257600080fd5b5061030f6107c13660046130cb565b6114e0565b3480156107d257600080fd5b5061030f6107e13660046134e7565b611537565b3480156107f257600080fd5b506102e261080136600461316e565b6115b5565b34801561081257600080fd5b5061030f6108213660046130cb565b6115e3565b34801561083257600080fd5b506102ac610841366004613557565b61169a565b60175460009060ff16156108755760405162461bcd60e51b815260040161086c90613ba3565b60405180910390fd5b610884858585856000806116de565b95945050505050565b6001600160e01b03191660009081526020819052604090205460ff1690565b60175460ff16156108cf5760405162461bcd60e51b815260040161086c90613ba3565b816108e16108db6117da565b826117e4565b6108fd5760405162461bcd60e51b815260040161086c90613c90565b6109078383611861565b505050565b60068054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156109985780601f1061096d57610100808354040283529160200191610998565b820191906000526020600020905b81548152906001019060200180831161097b57829003601f168201915b505050505090505b90565b60006109ae82611918565b6109ca5760405162461bcd60e51b815260040161086c90613c33565b506000908152600460205260409020546001600160a01b031690565b60006109f182610de4565b9050806001600160a01b0316836001600160a01b03161415610a255760405162461bcd60e51b815260040161086c90613cb3565b806001600160a01b0316610a376117da565b6001600160a01b03161480610a535750610a53816108016117da565b610a6f5760405162461bcd60e51b815260040161086c90613ab7565b6109078383611925565b610a816117da565b6009546001600160a01b03908116911614610aae5760405162461bcd60e51b815260040161086c90613a5c565b610907838383611993565b6000610ac56002611aa0565b905090565b610ad56108db6117da565b610af15760405162461bcd60e51b815260040161086c90613ab7565b610907838383611aab565b60009081526016602052604090205490565b60175460009060ff1615610b345760405162461bcd60e51b815260040161086c90613ba3565b610b4484848460008060006116de565b949350505050565b6001600160a01b0382166000908152600160205260408120610b6e9083611b2c565b90505b92915050565b60175460ff1615610b9a5760405162461bcd60e51b815260040161086c90613ba3565b81610ba36117da565b6000828152601160205260409020546001600160a01b03908116911614610bdc5760405162461bcd60e51b815260040161086c90613add565b5060009182526013602052604090912080546001600160a01b0319166001600160a01b03909216919091179055565b610c136117da565b6009546001600160a01b03908116911614610c405760405162461bcd60e51b815260040161086c90613a5c565b610907838383611b38565b610907838383604051806020016040528060008152506112c5565b60606040518060600160405280602e8152602001613daf602e9139905090565b600080610c94600284611c93565b509392505050565b610ca46117da565b6009546001600160a01b03908116911614610cd15760405162461bcd60e51b815260040161086c90613a5c565b610cdb8282611cb1565b5050565b600a546001600160a01b0390811691161490565b6000908152601160205260409020546001600160a01b031690565b60006002600b541415610d335760405162461bcd60e51b815260040161086c90613c59565b6002600b5560175460ff1615610d5b5760405162461bcd60e51b815260040161086c90613ba3565b610d6b8989898989898989611d29565b6001600b559998505050505050505050565b60006002600b541415610da25760405162461bcd60e51b815260040161086c90613c59565b6002600b5560175460ff1615610dca5760405162461bcd60e51b815260040161086c90613ba3565b610dda610dd56117da565b611d7e565b90506001600b5590565b6000610b71826040518060400160405280600c81526020016b4552433732313a452d34303560a01b8152506002611e1e9092919063ffffffff16565b610e286117da565b6009546001600160a01b03908116911614610e555760405162461bcd60e51b815260040161086c90613a5c565b600f80546001600160a01b0319166001600160a01b0383169081179091556040517f5ce0e6b7fd36339ee97339831b6c72694ecee88c62aab49919d9cabe0a732e4190600090a250565b60175460ff1615610ec25760405162461bcd60e51b815260040161086c90613ba3565b610ed187878787878787611e35565b50505050505050565b60006001600160a01b038216610f025760405162461bcd60e51b815260040161086c90613836565b6001600160a01b0382166000908152600160205260409020610b7190611aa0565b610f2b6117da565b6009546001600160a01b03908116911614610f585760405162461bcd60e51b815260040161086c90613a5c565b6009546040516000916001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600980546001600160a01b0319169055565b6000610b7182611fe6565b600a546001600160a01b031681565b60006002600b541415610fe15760405162461bcd60e51b815260040161086c90613c59565b6002600b5560175460ff16156110095760405162461bcd60e51b815260040161086c90613ba3565b61101282612020565b6001600b5592915050565b6001600160a01b031660009081526014602052604090205490565b6009546001600160a01b031690565b60175460009060ff161561106d5760405162461bcd60e51b815260040161086c90613ba3565b61107b8787878787876116de565b979650505050505050565b60078054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156109985780601f1061096d57610100808354040283529160200191610998565b6110ef6117da565b6001600160a01b0316826001600160a01b031614156111205760405162461bcd60e51b815260040161086c90613cb3565b806005600061112d6117da565b6001600160a01b03908116825260208083019390935260409182016000908120918716808252919093529120805460ff1916921515929092179091556111716117da565b6001600160a01b03167f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31836040516111a9919061376d565b60405180910390a35050565b60009081526012602052604090205490565b6111cf6117da565b6009546001600160a01b039081169116146111fc5760405162461bcd60e51b815260040161086c90613a5c565b600c80546001600160a01b0319166001600160a01b0383169081179091556040517ff28fa0fe2abe5dad2066ebce6edc9d403e4facb3603e47e6c0e7ea3e57dfe03290600090a250565b61124e6117da565b6009546001600160a01b0390811691161461127b5760405162461bcd60e51b815260040161086c90613a5c565b600d80546001600160a01b0319166001600160a01b0383169081179091556040517f62ff39aed768a426c7582b6e1062ab2631df1869b2d574e36f8274d2e2b0ab8190600090a250565b6112d66112d06117da565b836117e4565b6112f25760405162461bcd60e51b815260040161086c90613ab7565b6112fe84848484612252565b50505050565b606061130f82611918565b61132b5760405162461bcd60e51b815260040161086c90613c33565b60008281526008602090815260409182902080548351601f6002600019610100600186161502019093169290920491820184900484028101840190945280845290918301828280156113be5780601f10611393576101008083540402835291602001916113be565b820191906000526020600020905b8154815290600101906020018083116113a157829003601f168201915b50505050509050919050565b60175460ff16156113ed5760405162461bcd60e51b815260040161086c90613ba3565b816113f66117da565b6000828152601160205260409020546001600160a01b0390811691161461142f5760405162461bcd60e51b815260040161086c90613add565b8261143b6108db6117da565b6114575760405162461bcd60e51b815260040161086c90613c90565b6112fe8484612285565b6114696117da565b6009546001600160a01b039081169116146114965760405162461bcd60e51b815260040161086c90613a5c565b600e80546001600160a01b0319166001600160a01b0383169081179091556040517f7ad4c1bc3e874ec0bf47846feb5648b384e8511dc9e5f9803578c9d2b4ec9e6e90600090a250565b6114e86117da565b6009546001600160a01b039081169116146115155760405162461bcd60e51b815260040161086c90613a5c565b600a80546001600160a01b0319166001600160a01b0392909216919091179055565b61153f6117da565b6009546001600160a01b0390811691161461156c5760405162461bcd60e51b815260040161086c90613a5c565b6017805460ff19168215151790556040517fa9bfed3d98385b3777389e321dbde773cf7d335fa604fefbae3dca93564f5586906115aa90839061376d565b60405180910390a150565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205460ff1690565b6115eb6117da565b6009546001600160a01b039081169116146116185760405162461bcd60e51b815260040161086c90613a5c565b6001600160a01b03811661163e5760405162461bcd60e51b815260040161086c906137cd565b6009546040516001600160a01b038084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3600980546001600160a01b0319166001600160a01b0392909216919091179055565b60009081526015602052604090205490565b6000601836108015906116c357506116c333610cdf565b156116d7575060131936013560601c6109a0565b50336109a0565b60006116ea60106122ea565b6116f460106122f3565b90506117108682604051806020016040528060008152506122f7565b600081815260116020526040902080546001600160a01b0319166001600160a01b038916179055611741818661232a565b8215611751576117518184612285565b8115611761576117618183611861565b83156117d057600e546040516315aea5d760e01b81526001600160a01b03909116906315aea5d79061179d90309085908c908a906004016136d8565b600060405180830381600087803b1580156117b757600080fd5b505af11580156117cb573d6000803e3d6000fd5b505050505b9695505050505050565b6000610ac56116ac565b60006117ef82611918565b61180b5760405162461bcd60e51b815260040161086c90613c33565b600061181683610de4565b9050806001600160a01b0316846001600160a01b031614806118515750836001600160a01b0316611846846109a3565b6001600160a01b0316145b80610b445750610b4481856115b5565b600d54604051636a5fcc8b60e11b81526001600160a01b039091169063d4bf991690611897903090869086151590600401613702565b600060405180830381600087803b1580156118b157600080fd5b505af11580156118c5573d6000803e3d6000fd5b50505060008381526015602052604090819020839055518391507fe23ea816dce6d7f5c0b85cbd597e7c3b97b2453791152c0b94e5e5c5f314d2f09061190c908490613cd9565b60405180910390a25050565b6000610b7160028361236e565b600081815260046020526040902080546001600160a01b0319166001600160a01b038416908117909155819061195a82610de4565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6001600160a01b0383166119b95760405162461bcd60e51b815260040161086c90613813565b6040516370a0823160e01b815281906001600160a01b038416906370a08231906119e7903090600401613614565b60206040518083038186803b1580156119ff57600080fd5b505afa158015611a13573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a37919061356f565b1061090757611a506001600160a01b038316848361237a565b816001600160a01b0316836001600160a01b03167f6c9d637297625e945b296ff73a71fcfbd0a9e062652b6491a921c4c60194176b83604051611a939190613cd9565b60405180910390a3505050565b6000610b71826122f3565b600081815260156020526040808220829055600d549051636a5fcc8b60e11b81526001600160a01b039091169163d4bf991691611aef913091869190600401613702565b600060405180830381600087803b158015611b0957600080fd5b505af1158015611b1d573d6000803e3d6000fd5b505050506109078383836123d0565b6000610b6e83836124d3565b6001600160a01b038316611b5e5760405162461bcd60e51b815260040161086c90613813565b6040516331a9108f60e11b815230906001600160a01b03841690636352211e90611b8c908590600401613cd9565b60206040518083038186803b158015611ba457600080fd5b505afa158015611bb8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bdc91906130e7565b6001600160a01b03161415610907576040516323b872dd60e01b81526001600160a01b038316906323b872dd90611c1b9030908790869060040161365b565b600060405180830381600087803b158015611c3557600080fd5b505af1158015611c49573d6000803e3d6000fd5b5050505080826001600160a01b0316846001600160a01b03167ffefe036cac4ee3a4aca074a81cbcc4376e1484693289078dbec149c890101d5b60405160405180910390a4505050565b6000808080611ca28686612518565b909450925050505b9250929050565b6001600160a01b038216611cd75760405162461bcd60e51b815260040161086c90613813565b804710610cdb57611cf16001600160a01b03831682612574565b816001600160a01b03167eddb683bb45cd5d0ad8a200c6fae7152b1c236ee90a4a37db692407f5cc38bd8260405161190c9190613cd9565b600f546000906001600160a01b0316611d545760405162461bcd60e51b815260040161086c90613b37565b611d63898988856000806116de565b9050611d72818686868b612610565b98975050505050505050565b6001600160a01b03811660009081526014602052604081205480611db45760405162461bcd60e51b815260040161086c90613b80565b6001600160a01b038316600081815260146020526040812055611dd79082612574565b826001600160a01b03167f8fbbda19f4a70036f6f585dc4160142a8fa2a20ffb9393d23274f78de4e3988882604051611e109190613cd9565b60405180910390a250919050565b6000611e2b84848461273d565b90505b9392505050565b828114611e545760405162461bcd60e51b815260040161086c90613893565b308360005b81811015611fda57611e6b60106122ea565b6000611e7760106122f3565b9050611e938b82604051806020016040528060008152506122f7565b600081815260116020526040902080546001600160a01b0319166001600160a01b038d16179055611f1681898985818110611eca57fe5b9050602002810190611edc9190613d01565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061232a92505050565b8815611f2657611f26818a612285565b6000868684818110611f3457fe5b9050602002013590506000811115611f5057611f508282611861565b8a15611fd057600e60009054906101000a90046001600160a01b03166001600160a01b03166315aea5d786848f8f6040518563ffffffff1660e01b8152600401611f9d94939291906136d8565b600060405180830381600087803b158015611fb757600080fd5b505af1158015611fcb573d6000803e3d6000fd5b505050505b5050600101611e59565b50505050505050505050565b6000818152601360205260408120546001600160a01b031680610b715750506000908152601160205260409020546001600160a01b031690565b6000818152601560205260408120548061204c5760405162461bcd60e51b815260040161086c9061396d565b8034101561206c5760405162461bcd60e51b815260040161086c9061394a565b8060008061207986610de4565b905060006120856117da565b9050600061209288611fe6565b6000898152601260209081526040808320546016909252909120549192509081158015906120c05750600081115b80156120cb57508088115b156120f7576120e86127106120e2838b038561279c565b906127d6565b95506120f48787612818565b96505b60008a8152601660205260409020889055600c546001600160a01b03161561218857600c546040516345c984d960e11b81526001600160a01b0390911690638b9309b2906121559030908e908a908a908f908b908f90600401613698565b600060405180830381600087803b15801561216f57600080fd5b505af1158015612183573d6000803e3d6000fd5b505050505b85156121cb576001600160a01b0383166000908152601460205260409020546121b1908761285a565b6001600160a01b0384166000908152601460205260409020555b6121d685858c611aab565b6121e96001600160a01b03861688612574565b836001600160a01b0316856001600160a01b03168b7f71a2ee63bc7695052e3a9837d5a45dd1cc0ce12717e39cef6eb6afb0d91697ed8b878b60405161223193929190613ce2565b60405180910390a46122428861287f565b5060019998505050505050505050565b61225d848484611aab565b612269848484846128ae565b6112fe5760405162461bcd60e51b815260040161086c906139b3565b611f408111156122a75760405162461bcd60e51b815260040161086c90613990565b600082815260126020526040908190208290555182907fd91bd92b973231f564eaa17c9bc62c86b96a8885f3cdcb990d5a3f0415580d909061190c908490613cd9565b80546001019055565b5490565b6123018383612996565b61230e60008484846128ae565b6109075760405162461bcd60e51b815260040161086c906139b3565b61233382611918565b61234f5760405162461bcd60e51b815260040161086c90613c33565b6000828152600860209081526040909120825161090792840190612f78565b6000610b6e8383612a4e565b6109078363a9059cbb60e01b848460405160240161239992919061367f565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152612a66565b826001600160a01b03166123e382610de4565b6001600160a01b0316146124095760405162461bcd60e51b815260040161086c90613b5a565b6001600160a01b03821661242f5760405162461bcd60e51b815260040161086c90613836565b61243a600082611925565b6001600160a01b038316600090815260016020526040902061245c9082612af5565b506001600160a01b038216600090815260016020526040902061247f9082612b01565b5061248c60028284612b0d565b5080826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a4505050565b815460009082106124f65760405162461bcd60e51b815260040161086c9061378b565b82600001828154811061250557fe5b9060005260206000200154905092915050565b81546000908190831061253d5760405162461bcd60e51b815260040161086c906139d9565b600084600001848154811061254e57fe5b906000526020600020906002020190508060000154816001015492509250509250929050565b804710156125945760405162461bcd60e51b815260040161086c90613913565b6000826001600160a01b0316826040516125ad906109a0565b60006040518083038185875af1925050503d80600081146125ea576040519150601f19603f3d011682016040523d82523d6000602084013e6125ef565b606091505b50509050806109075760405162461bcd60e51b815260040161086c906138b6565b61262261261b6117da565b8484612b23565b600f5460405163095ea7b360e01b81526001600160a01b038581169263095ea7b3926126569290911690869060040161367f565b602060405180830381600087803b15801561267057600080fd5b505af1158015612684573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126a89190613503565b50600f546040516305eef16560e11b81526001600160a01b0390911690630bdde2ca906126e390309089908990899089908990600401613725565b602060405180830381600087803b1580156126fd57600080fd5b505af1158015612711573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612735919061356f565b505050505050565b6000828152600184016020526040812054828161276d5760405162461bcd60e51b815260040161086c9190613778565b5084600001600182038154811061278057fe5b9060005260206000209060020201600101549150509392505050565b6000826127ab57506000610b71565b828202828482816127b857fe5b0414610b6e5760405162461bcd60e51b815260040161086c90613a1b565b6000610b6e83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250612c62565b6000610b6e83836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250612c99565b600082820183811015610b6e5760405162461bcd60e51b815260040161086c9061385c565b600061288b3483612818565b90508015610cdb57610cdb8161289f6117da565b6001600160a01b031690612574565b60006128c2846001600160a01b0316612cc5565b6128ce57506001610b44565b606061295f630a85bd0160e11b6128e36117da565b8887876040516024016128f99493929190613628565b60408051601f19818403018152918152602080830180516001600160e01b03166001600160e01b0319909516949094179093528051808201909152600c81526b22a9219b99189d22969a181960a11b928101929092526001600160a01b03881691612cfe565b9050600081806020019051810190612977919061353b565b6001600160e01b031916630a85bd0160e11b1492505050949350505050565b6001600160a01b0382166129bc5760405162461bcd60e51b815260040161086c90613836565b6129c581611918565b156129e25760405162461bcd60e51b815260040161086c90613a91565b6001600160a01b0382166000908152600160205260409020612a049082612b01565b50612a1160028284612b0d565b5060405181906001600160a01b038416906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b60009081526001919091016020526040902054151590565b6060612abb826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316612cfe9092919063ffffffff16565b8051909150156109075780806020019051810190612ad99190613503565b6109075760405162461bcd60e51b815260040161086c90613bc6565b6000610b6e8383612d0d565b6000610b6e8383612dd3565b6000610b4484846001600160a01b038516612e1d565b6040516370a0823160e01b81526000906001600160a01b038416906370a0823190612b52908790600401613614565b60206040518083038186803b158015612b6a57600080fd5b505afa158015612b7e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ba2919061356f565b905080821115612bc45760405162461bcd60e51b815260040161086c90613b80565b6040516323b872dd60e01b81526001600160a01b038416906323b872dd90612bf49087903090879060040161365b565b602060405180830381600087803b158015612c0e57600080fd5b505af1158015612c22573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c469190613503565b6112fe5760405162461bcd60e51b815260040161086c90613c10565b60008183612c835760405162461bcd60e51b815260040161086c9190613778565b506000838581612c8f57fe5b0495945050505050565b60008184841115612cbd5760405162461bcd60e51b815260040161086c9190613778565b505050900390565b6000813f7fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470818114801590610b44575050151592915050565b6060610b448484600085612eb4565b60008181526001830160205260408120548015612dc95783546000198083019190810190600090879083908110612d4057fe5b9060005260206000200154905080876000018481548110612d5d57fe5b600091825260208083209091019290925582815260018981019092526040902090840190558654879080612d8d57fe5b60019003818190600052602060002001600090559055866001016000878152602001908152602001600020600090556001945050505050610b71565b6000915050610b71565b6000612ddf8383612a4e565b612e1557508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610b71565b506000610b71565b600082815260018401602052604081205480612e82575050604080518082018252838152602080820184815286546001818101895560008981528481209551600290930290950191825591519082015586548684528188019092529290912055611e2e565b82856000016001830381548110612e9557fe5b9060005260206000209060020201600101819055506000915050611e2e565b6060612ebf85612cc5565b612edb5760405162461bcd60e51b815260040161086c90613b00565b60006060866001600160a01b03168587604051612ef891906135f8565b60006040518083038185875af1925050503d8060008114612f35576040519150601f19603f3d011682016040523d82523d6000602084013e612f3a565b606091505b50915091508115612f4e579150610b449050565b805115612f5e5780518082602001fd5b8360405162461bcd60e51b815260040161086c9190613778565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10612fb957805160ff1916838001178555612fe6565b82800160010185558215612fe6579182015b82811115612fe6578251825591602001919060010190612fcb565b50612ff2929150612ff6565b5090565b5b80821115612ff25760008155600101612ff7565b60008083601f84011261301c578182fd5b50813567ffffffffffffffff811115613033578182fd5b6020830191508360208083028501011115611caa57600080fd5b600082601f83011261305d578081fd5b813567ffffffffffffffff80821115613074578283fd5b604051601f8301601f191681016020018281118282101715613094578485fd5b6040528281529250828483016020018610156130af57600080fd5b8260208601602083013760006020848301015250505092915050565b6000602082840312156130dc578081fd5b8135610b6e81613d72565b6000602082840312156130f8578081fd5b8151610b6e81613d72565b600080600060608486031215613117578182fd5b833561312281613d72565b9250602084013561313281613d72565b929592945050506040919091013590565b60008060408385031215613155578182fd5b823561316081613d72565b946020939093013593505050565b60008060408385031215613180578182fd5b823561318b81613d72565b9150602083013561319b81613d72565b809150509250929050565b600080600080600080600080610100898b0312156131c2578384fd5b88356131cd81613d72565b975060208901356131dd81613d72565b965060408901356131ed81613d72565b9550606089013567ffffffffffffffff80821115613209578586fd5b6132158c838d0161304d565b965060808b013591508082111561322a578586fd5b506132378b828c0161304d565b94505060a089013561324881613d72565b979a969950949793969295929450505060c08201359160e0013590565b600080600060608486031215613279578283fd5b833561328481613d72565b9250602084013561329481613d72565b9150604084013567ffffffffffffffff8111156132af578182fd5b6132bb8682870161304d565b9150509250925092565b600080600080608085870312156132da578384fd5b84356132e581613d72565b935060208501356132f581613d72565b9250604085013567ffffffffffffffff811115613310578283fd5b61331c8782880161304d565b949793965093946060013593505050565b60008060008060008060c08789031215613345578182fd5b863561335081613d72565b9550602087013561336081613d72565b9450604087013567ffffffffffffffff81111561337b578283fd5b61338789828a0161304d565b945050606087013592506080870135915060a087013590509295509295509295565b600080600060608486031215613117578081fd5b600080600080608085870312156133d2578182fd5b84356133dd81613d72565b935060208501356133ed81613d72565b925060408501359150606085013567ffffffffffffffff81111561340f578182fd5b61341b8782880161304d565b91505092959194509250565b60008060408385031215613439578182fd5b823561344481613d72565b9150602083013561319b81613d8a565b600080600080600080600060a0888a03121561346e578081fd5b873561347981613d72565b96506020880135955060408801359450606088013567ffffffffffffffff808211156134a3578283fd5b6134af8b838c0161300b565b909650945060808a01359150808211156134c7578283fd5b506134d48a828b0161300b565b989b979a50959850939692959293505050565b6000602082840312156134f8578081fd5b8135610b6e81613d8a565b600060208284031215613514578081fd5b8151610b6e81613d8a565b600060208284031215613530578081fd5b8135610b6e81613d98565b60006020828403121561354c578081fd5b8151610b6e81613d98565b600060208284031215613568578081fd5b5035919050565b600060208284031215613580578081fd5b5051919050565b60008060408385031215613599578182fd5b82359150602083013561319b81613d72565b600080604083850312156135bd578182fd5b50508035926020909101359150565b600081518084526135e4816020860160208601613d46565b601f01601f19169290920160200192915050565b6000825161360a818460208701613d46565b9190910192915050565b6001600160a01b0391909116815260200190565b6001600160a01b03858116825284166020820152604081018390526080606082018190526000906117d0908301846135cc565b6001600160a01b039384168152919092166020820152604081019190915260600190565b6001600160a01b03929092168252602082015260400190565b6001600160a01b039788168152602081019690965293861660408601529185166060850152608084015290921660a082015260c081019190915260e00190565b6001600160a01b039485168152602081019390935292166040820152606081019190915260800190565b6001600160a01b0393909316835260208301919091521515604082015260600190565b600060018060a01b03808916835287602084015260c0604084015261374d60c08401886135cc565b9581166060840152608083019490945250911660a0909101529392505050565b901515815260200190565b600060208252610b6e60208301846135cc565b60208082526022908201527f456e756d657261626c655365743a20696e646578206f7574206f6620626f756e604082015261647360f01b606082015260800190565b60208082526026908201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160408201526564647265737360d01b606082015260800190565b6020808252600990820152684248503a452d34303360b81b604082015260600190565b6020808252600c908201526b4552433732313a452d34303360a01b604082015260600190565b6020808252601b908201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604082015260600190565b60208082526009908201526828292a1d229699181960b91b604082015260600190565b6020808252603a908201527f416464726573733a20756e61626c6520746f2073656e642076616c75652c207260408201527f6563697069656e74206d61792068617665207265766572746564000000000000606082015260800190565b6020808252601d908201527f416464726573733a20696e73756666696369656e742062616c616e6365000000604082015260600190565b6020808252600990820152681414950e914b4d0c4d60ba1b604082015260600190565b60208082526009908201526828292a1d22969a189b60b91b604082015260600190565b6020808252600990820152685052543a452d34323160b81b604082015260600190565b6020808252600c908201526b22a9219b99189d22969a181960a11b604082015260600190565b60208082526022908201527f456e756d657261626c654d61703a20696e646578206f7574206f6620626f756e604082015261647360f01b606082015260800190565b60208082526021908201527f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f6040820152607760f81b606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b6020808252600c908201526b4552433732313a452d34303760a01b604082015260600190565b6020808252600c908201526b4552433732313a452d31303560a01b604082015260600190565b6020808252600990820152681414950e914b4c4c0d60ba1b604082015260600190565b6020808252601d908201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604082015260600190565b6020808252600990820152685052543a452d31303760b81b604082015260600190565b6020808252600c908201526b22a9219b99189d229698981960a11b604082015260600190565b6020808252600990820152685052543a452d34313160b81b604082015260600190565b6020808252600990820152685052543a452d31303160b81b604082015260600190565b6020808252602a908201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6040820152691bdd081cdd58d8d9595960b21b606082015260800190565b6020808252600990820152685052543a452d34303160b81b604082015260600190565b6020808252600c908201526b4552433732313a452d34303560a01b604082015260600190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b6020808252600990820152685052543a452d31303560b81b604082015260600190565b6020808252600c908201526b4552433732313a452d31313160a01b604082015260600190565b90815260200190565b9283526001600160a01b03919091166020830152604082015260600190565b6000808335601e19843603018112613d17578283fd5b83018035915067ffffffffffffffff821115613d31578283fd5b602001915036819003821315611caa57600080fd5b60005b83811015613d61578181015183820152602001613d49565b838111156112fe5750506000910152565b6001600160a01b0381168114613d8757600080fd5b50565b8015158114613d8757600080fd5b6001600160e01b031981168114613d8757600080fdfe312e302e302d626574612e312f636861726765642d7061727469636c65732e72656c61792e726563697069656e74a264697066735822122016660aa8bf936e54e27422910ae6d21205afa3a8cb2e0aab3cb1c1fcc57928d064736f6c634300060c0033

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.