ETH Price: $2,883.60 (-8.97%)
Gas: 9 Gwei

Contract

0x44BeA25aAc16A73112239bb7c222757BbEb35821
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Value
0x60a06040191048542024-01-28 11:51:23158 days ago1706442683IN
 Create: SalesManager
0 ETH0.0471566212.00743147

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
SalesManager

Compiler Version
v0.8.17+commit.8df45f5f

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
File 1 of 44 : SalesManager.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity 0.8.17;

import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20BurnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/cryptography/ECDSAUpgradeable.sol";
import "@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol";
import "@uniswap/v3-periphery/contracts/libraries/TransferHelper.sol";

import "../interfaces/ISalesManager.sol";
import "./libraries/LibIMPT.sol";

import "./libraries/SigRecovery.sol";

contract SalesManager is ISalesManager, PausableUpgradeable, UUPSUpgradeable {
  using SafeERC20Upgradeable for IERC20Upgradeable;

  IERC20Upgradeable public override IMPTAddress;
  IERC20Upgradeable public override USDCAddress;
  IWETH public override WETHAddress;
  ICarbonCreditNFT public override CarbonCreditNFTContract;
  ISoulboundToken public override SoulboundToken;
  IAccessManager public override AccessManager;

  address public override IMPTTreasuryAddress;

  // Request ID (from back-end) => used
  mapping(bytes24 => bool) public override usedRequests;

  ISwapRouter public override SwapRouter;

  // for a given token id - must have 18 decimals
  mapping(uint256 => uint256) public override burnAmounts;

  // tracks user claim methods
  mapping(bytes24 => bool) public override usedClaims;

  modifier onlyIMPTRole(bytes32 _role, IAccessManager _AccessManager) {
    LibIMPT._hasIMPTRole(_role, msg.sender, AccessManager);
    _;
  }

  function initialize(ConstructorParams memory _params) public initializer {
    PausableUpgradeable.__Pausable_init();
    LibIMPT._checkZeroAddress(address(_params.IMPTAddress));
    LibIMPT._checkZeroAddress(address(_params.USDCAddress));
    LibIMPT._checkZeroAddress(address(_params.WETHAddress));
    LibIMPT._checkZeroAddress(address(_params.CarbonCreditNFTContract));
    LibIMPT._checkZeroAddress(address(_params.AccessManager));
    LibIMPT._checkZeroAddress(address(_params.SoulboundToken));
    LibIMPT._checkZeroAddress(_params.IMPTTreasuryAddress);
    __UUPSUpgradeable_init();

    IMPTAddress = _params.IMPTAddress;
    USDCAddress = _params.USDCAddress;
    WETHAddress = _params.WETHAddress;
    IMPTTreasuryAddress = _params.IMPTTreasuryAddress;
    CarbonCreditNFTContract = _params.CarbonCreditNFTContract;
    AccessManager = _params.AccessManager;
    SoulboundToken = _params.SoulboundToken;
  }

  //############################
  //#### INTERNAL-FUNCTIONS ####

  /// @dev Verifies the purchase signature of the given authorisation parameters.
  /// @param _authorisationParams Authorisation parameters to verify the signature of.
  function _verifyPurchaseSignature(
    AuthorisationParams memory _authorisationParams
  ) internal {
    bytes memory encodedTransferRequest = abi.encode(
      _authorisationParams.requestId,
      _authorisationParams.expiry,
      msg.sender,
      _authorisationParams.sellAmount,
      _authorisationParams.amount,
      _authorisationParams.burnPercentage,
      _authorisationParams.claimPercentage,
      _authorisationParams.swapPath,
      _authorisationParams.minimumSwapAmount,
      _authorisationParams.userAddress
    );
    if (_authorisationParams.expiry < block.timestamp) {
      revert LibIMPT.SignatureExpired();
    }
    if (usedRequests[_authorisationParams.requestId]) {
      revert LibIMPT.InvalidSignature();
    }

    address recoveredAddress = SigRecovery.recoverAddressFromMessage(
      encodedTransferRequest,
      _authorisationParams.signature
    );

    if (!AccessManager.hasRole(LibIMPT.IMPT_BACKEND_ROLE, recoveredAddress)) {
      revert LibIMPT.InvalidSignature();
    }

    usedRequests[_authorisationParams.requestId] = true;
  }

  /// @dev Calls the given DEX swap contract with the given parameters and audits the results.
  /// @param _swapParams Swap parameters to pass to the DEX contract.
  /// @return  swapReturn The resulting swap data.
  function _callDEXSwap(
    SwapParams calldata _swapParams
  ) internal returns (SwapReturnData memory swapReturn) {
    //Sticking these in memory so we don't repetitively read storage
    IERC20Upgradeable USDCToken = USDCAddress;
    IERC20Upgradeable IMPTToken = IMPTAddress;

    if (
      !(
        AccessManager.hasRole(LibIMPT.IMPT_APPROVED_DEX, _swapParams.swapTarget)
      )
    ) {
      revert UnauthorisedSwapTarget();
    }
    //If the DEX being utilised for the swap will take the funds from an address other than the call target, grant it a temporary allowance
    if (_swapParams.swapTarget != _swapParams.spender) {
      IMPTToken.approve(_swapParams.spender, type(uint256).max);
    }

    uint256 USDCBefore = USDCToken.balanceOf(address(this));
    uint256 IMPTBefore = IMPTToken.balanceOf(address(this));

    (bool success, ) = _swapParams.swapTarget.call(_swapParams.swapCallData);

    if (!success) {
      revert ZeroXSwapFailed();
    }
    swapReturn.USDCDelta = USDCToken.balanceOf(address(this)) - USDCBefore;
    swapReturn.IMPTDelta = IMPTBefore - IMPTToken.balanceOf(address(this));

    if (_swapParams.swapTarget != _swapParams.spender) {
      IMPTToken.approve(_swapParams.spender, uint256(0));
    }
  }

  /// @dev Audits the results of a swap to ensure that the correct amounts of sell and buy tokens were transferred.
  /// @param _swapReturnData Swap data to audit.
  /// @param _sellAmount Amount of sell tokens that should have been transferred.
  function _auditSwap(
    SwapReturnData memory _swapReturnData,
    uint256 _sellAmount
  ) internal pure {
    if (_swapReturnData.IMPTDelta != _sellAmount) {
      revert WrongSellTokenChange();
    }
    if (!(_swapReturnData.USDCDelta > 0)) {
      revert WrongBuyTokenChange();
    }
  }

  //###################
  //#### FUNCTIONS ####
  /// @dev This function is to check that the upgrade functions in UUPSUpgradeable are being called by an address with the correct role
  function _authorizeUpgrade(
    address newImplementation
  ) internal override onlyIMPTRole(LibIMPT.IMPT_ADMIN_ROLE, AccessManager) {}

  receive() external payable override {}

  // marker
  function purchaseWithIMPT(
    AuthorisationParams calldata _authorisationParams,
    SwapParams calldata _swapParams
  ) external whenNotPaused {
    _verifyPurchaseSignature(_authorisationParams);

    IMPTAddress.safeTransferFrom(
      msg.sender,
      address(this),
      _authorisationParams.sellAmount
    );

    SwapReturnData memory swapReturn = _callDEXSwap(_swapParams);
    _auditSwap(swapReturn, _authorisationParams.sellAmount);

    emit PurchaseCompleted(
      _authorisationParams.requestId,
      swapReturn.USDCDelta
    );

    USDCAddress.transfer(IMPTTreasuryAddress, swapReturn.USDCDelta);

    CarbonCreditNFTContract.mint(
      msg.sender,
      _authorisationParams.tokenId,
      _authorisationParams.amount,
      _authorisationParams.signature
    );
  }

  function overrideBurnAmount(
    uint256 _tokenId,
    uint256 _burnAmount
  ) external override onlyIMPTRole(LibIMPT.IMPT_ADMIN_ROLE, AccessManager) {
    burnAmounts[_tokenId] = _burnAmount;
  }

  function updateBurnAmount(
    uint256 _tokenId,
    uint256 _burnAmount
  ) external override onlyIMPTRole(LibIMPT.IMPT_ADMIN_ROLE, AccessManager) {
    burnAmounts[_tokenId] += _burnAmount;
  }

  function bulkUpdateBurnAmount(
    uint256[] calldata _tokenIds,
    uint256[] calldata _burnAmounts
  ) external override onlyIMPTRole(LibIMPT.IMPT_ADMIN_ROLE, AccessManager) {
    for (uint256 i; i < _tokenIds.length; ) {
      burnAmounts[_tokenIds[i]] += _burnAmounts[i];
      unchecked {
        ++i;
      }
    }
  }

  function purchaseWithIMPTWithoutSwap(
    AuthorisationParams calldata _authorisationParams
  ) external whenNotPaused {
    _verifyPurchaseSignature(_authorisationParams);

    // the _authorisationParams.burnPercentage is the percentage of _authorisationParams.sellAmount
    // to keep in this contract
    uint256 burnAmount = ((_authorisationParams.sellAmount *
      _authorisationParams.burnPercentage) / 100);

    burnAmounts[_authorisationParams.tokenId] += burnAmount;

    // web 3 user pays in IMPT
    if (_authorisationParams.userAddress == address(0)) {
      // keep the burn amount in this contract
      IMPTAddress.safeTransferFrom(msg.sender, address(this), burnAmount);

      // transfer the rest of the IMPT to the treasury address (if burn is not 100%)
      if (_authorisationParams.sellAmount - burnAmount > 0) {
        IMPTAddress.safeTransferFrom(
          msg.sender,
          IMPTTreasuryAddress,
          _authorisationParams.sellAmount - burnAmount
        );
      }
    }

    emit PurchaseCompleted(
      _authorisationParams.requestId,
      _authorisationParams.sellAmount
    );

    CarbonCreditNFTContract.mint(
      msg.sender,
      _authorisationParams.tokenId,
      _authorisationParams.amount,
      _authorisationParams.signature
    );
  }

  function retireAmount(
    ICarbonCreditNFT.RetirementParams calldata _retirementParams,
    uint256 _supply,
    address _user
  ) external override {
    require(
      msg.sender == address(CarbonCreditNFTContract),
      "SalesManager: only NFT contract can call this function"
    );

    // calculate the total amount of IMPT to burn for this retirement
    uint256 singleAmount = burnAmounts[_retirementParams.tokenId] / _supply;
    uint256 total = singleAmount * _retirementParams.amount;

    // we need to get the swap amount and claimable amount as percentages
    uint256 swapAmount = ((total * _retirementParams.swapPercentage) / 100);
    uint256 claimAmount = ((total * _retirementParams.claimPercentage) / 100);

    // this is the minimum amount of IMPT we need to receive from the swap
    uint256 minimumAmount = swapAmount + claimAmount;

    burnAmounts[_retirementParams.tokenId] -= total;

    ISwapRouter.ExactInputParams memory params = ISwapRouter.ExactInputParams({
      path: _retirementParams.swapPath,
      recipient: address(this),
      deadline: block.timestamp,
      amountIn: _retirementParams.usdcSwapAmount,
      amountOutMinimum: 0
    });

    uint256 amountOut = SwapRouter.exactInput(params);

    // if we don't get our minimum expected amount - revert
    require(amountOut >= minimumAmount, "SalesManager: swap amount too low");

    // burn our IMPT
    ERC20BurnableUpgradeable(address(IMPTAddress)).burn(total);

    // emit the claimable value
    emit UserRewardsClaimEligible(
      _retirementParams.tokenId,
      _retirementParams.amount,
      total,
      _retirementParams.claimPercentage,
      claimAmount,
      _user
    );
  }

  function purchaseSoulboundToken(
    AuthorisationParams memory _authorisationParams,
    string memory _imageURI
  ) external whenNotPaused {
    uint256 tokenId = SoulboundToken.getCurrentTokenId();

    _verifyPurchaseSignature(
      AuthorisationParams({
        requestId: _authorisationParams.requestId,
        expiry: _authorisationParams.expiry,
        sellAmount: _authorisationParams.sellAmount,
        tokenId: tokenId,
        amount: 1,
        signature: _authorisationParams.signature,
        burnPercentage: 0,
        userAddress: address(0),
        claimPercentage: 0,
        swapPath: _authorisationParams.swapPath,
        minimumSwapAmount: 0
      })
    );

    IMPTAddress.safeTransferFrom(
      msg.sender,
      IMPTTreasuryAddress,
      _authorisationParams.sellAmount
    );

    SoulboundToken.mint(msg.sender, _imageURI);
    emit SoulboundTokenMinted(msg.sender, tokenId);
  }

  function withdraw(
    uint256 _amount
  ) external onlyIMPTRole(LibIMPT.IMPT_ADMIN_ROLE, AccessManager) {
    _withdraw(_amount);
  }

  function _withdraw(uint256 _amount) internal {
    IMPTAddress.safeTransfer(IMPTTreasuryAddress, _amount);
  }

  //##########################
  //#### SETTER-FUNCTIONS ####
  function pause()
    external
    override
    onlyIMPTRole(LibIMPT.IMPT_ADMIN_ROLE, AccessManager)
  {
    _pause();
  }

  function unpause()
    external
    override
    onlyIMPTRole(LibIMPT.IMPT_ADMIN_ROLE, AccessManager)
  {
    _unpause();
  }

  function setPlatformToken(
    IERC20Upgradeable _implementation
  ) external override onlyIMPTRole(LibIMPT.IMPT_ADMIN_ROLE, AccessManager) {
    LibIMPT._checkZeroAddress(address(_implementation));
    IMPTAddress = _implementation;
    emit PlatformTokenChanged(_implementation);
  }

  function setUSDC(
    IERC20Upgradeable _implementation
  ) external override onlyIMPTRole(LibIMPT.IMPT_ADMIN_ROLE, AccessManager) {
    LibIMPT._checkZeroAddress(address(_implementation));
    USDCAddress = _implementation;
    emit USDCChanged(_implementation);
  }

  function setWETH(
    IWETH _implementation
  ) external override onlyIMPTRole(LibIMPT.IMPT_ADMIN_ROLE, AccessManager) {
    LibIMPT._checkZeroAddress(address(_implementation));
    WETHAddress = _implementation;
    emit WETHChanged(_implementation);
  }

  function addSwapTarget(
    address _implementation
  ) external override onlyIMPTRole(LibIMPT.IMPT_ADMIN_ROLE, AccessManager) {
    LibIMPT._checkZeroAddress(address(_implementation));
    AccessManager.grantRole(LibIMPT.IMPT_APPROVED_DEX, _implementation);
    IMPTAddress.approve(_implementation, type(uint256).max);
  }

  function removeSwapTarget(
    address _implementation
  ) external override onlyIMPTRole(LibIMPT.IMPT_ADMIN_ROLE, AccessManager) {
    LibIMPT._checkZeroAddress(address(_implementation));
    AccessManager.revokeRole(LibIMPT.IMPT_APPROVED_DEX, _implementation);
    IMPTAddress.approve(_implementation, uint256(0));
  }

  function setIMPTTreasury(
    address _implementation
  ) external override onlyIMPTRole(LibIMPT.IMPT_ADMIN_ROLE, AccessManager) {
    LibIMPT._checkZeroAddress(_implementation);
    IMPTTreasuryAddress = _implementation;
    emit LibIMPT.IMPTTreasuryChanged(_implementation);
  }

  function setCarbonCreditNFT(
    ICarbonCreditNFT _carbonCreditNFT
  ) external override onlyIMPTRole(LibIMPT.IMPT_ADMIN_ROLE, AccessManager) {
    LibIMPT._checkZeroAddress(address(_carbonCreditNFT));
    CarbonCreditNFTContract = _carbonCreditNFT;
    emit CarbonCreditNFTContractChanged(_carbonCreditNFT);
  }

  function setSoulboundToken(
    ISoulboundToken _soulboundToken
  ) external override onlyIMPTRole(LibIMPT.IMPT_ADMIN_ROLE, AccessManager) {
    LibIMPT._checkZeroAddress(address(_soulboundToken));
    SoulboundToken = _soulboundToken;
    emit SoulboundTokenContractChanged(_soulboundToken);
  }

  // some ERC1155ReceiverUpgradeable functions that allow this contract to receive ERC1155 tokens
  // (used in bulkPurchaseAndRetire function)
  function onERC1155Received(
    address,
    address,
    uint256,
    uint256,
    bytes memory
  ) public virtual returns (bytes4) {
    return this.onERC1155Received.selector;
  }

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

  function bulkPurchaseAndRetire(
    BulkPurchaseAndRetireParams calldata _bulkPurchaseAndRetireParams
  )
    external
    override
    whenNotPaused
    onlyIMPTRole(LibIMPT.IMPT_BACKEND_ROLE, AccessManager)
  {
    // construct what houses our data structures before the first loop
    uint256[] memory tokenIds = new uint256[](
      _bulkPurchaseAndRetireParams.bulkPurchaseAndRetire.length
    );
    uint256[] memory amounts = new uint256[](
      _bulkPurchaseAndRetireParams.bulkPurchaseAndRetire.length
    );

    // verify data and rip out to our data structures
    for (
      uint256 i;
      i < _bulkPurchaseAndRetireParams.bulkPurchaseAndRetire.length;

    ) {
      // if transfer amount is not zero, it's being purchased with IMPT
      // the _authorisationParams.burnPercentage is the percentage of _authorisationParams.sellAmount
      // to keep in this contract
      uint256 burnAmount = (_bulkPurchaseAndRetireParams
        .bulkPurchaseAndRetire[i]
        .sellAmount *
        _bulkPurchaseAndRetireParams.bulkPurchaseAndRetire[i].burnPercentage) /
        100;

      burnAmounts[
        _bulkPurchaseAndRetireParams.bulkPurchaseAndRetire[i].tokenId
      ] += burnAmount;

      // we need to get the swap amount and claimable amount as percentages
      uint256 swapAmount = ((burnAmount *
        _bulkPurchaseAndRetireParams.bulkPurchaseAndRetire[i].swapPercentage) /
        100);

      // with the new changes, we swap USDC in this contract to IMPT to then burn
      ISwapRouter.ExactInputParams memory params = ISwapRouter
        .ExactInputParams({
          path: _bulkPurchaseAndRetireParams.swapPath,
          recipient: address(this),
          deadline: block.timestamp,
          amountIn: _bulkPurchaseAndRetireParams
            .bulkPurchaseAndRetire[i]
            .usdcSwapAmount,
          amountOutMinimum: 0
        });

      uint256 amountOut = SwapRouter.exactInput(params);
      // if we don't get our minimum expected amount - revert
      require(
        amountOut >=
          swapAmount +
            ((burnAmount *
              _bulkPurchaseAndRetireParams
                .bulkPurchaseAndRetire[i]
                .claimPercentage) / 100), // this second part is the claimable amount
        "SalesManager: swap amount too low"
      );

      // burn the IMPT we just bought
      ERC20BurnableUpgradeable(address(IMPTAddress)).burn(amountOut);

      tokenIds[i] = _bulkPurchaseAndRetireParams
        .bulkPurchaseAndRetire[i]
        .tokenId;
      amounts[i] = _bulkPurchaseAndRetireParams.bulkPurchaseAndRetire[i].amount;

      // emit the claimable value for this burn and mint (this is before the burn takes place, but is more gas efficient)
      emit UserRewardsClaimEligible(
        _bulkPurchaseAndRetireParams.bulkPurchaseAndRetire[i].tokenId,
        _bulkPurchaseAndRetireParams.bulkPurchaseAndRetire[i].amount,
        burnAmount,
        _bulkPurchaseAndRetireParams.bulkPurchaseAndRetire[i].claimPercentage,
        ((burnAmount *
          _bulkPurchaseAndRetireParams
            .bulkPurchaseAndRetire[i]
            .claimPercentage) / 100), // claimable amount
        _bulkPurchaseAndRetireParams.bulkPurchaseAndRetire[i].userAddress
      );

      unchecked {
        ++i;
      }
    }

    // mint the tokens to this address
    CarbonCreditNFTContract.mintBatch(address(this), tokenIds, amounts, "");

    for (
      uint256 i;
      i < _bulkPurchaseAndRetireParams.bulkPurchaseAndRetire.length;

    ) {
      // emit events
      emit PurchaseCompleted(
        _bulkPurchaseAndRetireParams.bulkPurchaseAndRetire[i].requestId,
        _bulkPurchaseAndRetireParams.bulkPurchaseAndRetire[i].sellAmount
      );

      unchecked {
        ++i;
      }
    }

    // burn the carbon credit NFTs
    CarbonCreditNFTContract.bulkRetire(tokenIds, amounts);
  }

  function _verifyUserRewardClaimSignature(
    UserRewardClaim memory _userRewardClaim
  ) internal {
    bytes memory encodedTransferRequest = abi.encode(
      _userRewardClaim.requestId,
      _userRewardClaim.amount,
      msg.sender,
      _userRewardClaim.expiry
    );
    if (_userRewardClaim.expiry < block.timestamp) {
      revert LibIMPT.SignatureExpired();
    }
    if (usedClaims[_userRewardClaim.requestId]) {
      revert LibIMPT.InvalidSignature();
    }

    address recoveredAddress = SigRecovery.recoverAddressFromMessage(
      encodedTransferRequest,
      _userRewardClaim.signature
    );

    if (!AccessManager.hasRole(LibIMPT.IMPT_BACKEND_ROLE, recoveredAddress)) {
      revert LibIMPT.InvalidSignature();
    }

    // mark this request as claimed (prevent replay attacks)
    usedClaims[_userRewardClaim.requestId] = true;
  }

  function userRewardsClaim(
    UserRewardClaim calldata _rewardsClaim
  ) external override {
    _verifyUserRewardClaimSignature(_rewardsClaim);

    IMPTAddress.transfer(msg.sender, _rewardsClaim.amount);

    emit UserRewardClaimed(
      _rewardsClaim.requestId,
      msg.sender,
      _rewardsClaim.amount
    );
  }

  function setUniswapRouter(
    address _uniswapRouter
  ) external override onlyIMPTRole(LibIMPT.IMPT_ADMIN_ROLE, AccessManager) {
    LibIMPT._checkZeroAddress(_uniswapRouter);
    SwapRouter = ISwapRouter(_uniswapRouter);
  }

  function approveUniswapRouter(
    address _router
  ) external override onlyIMPTRole(LibIMPT.IMPT_ADMIN_ROLE, AccessManager) {
    LibIMPT._checkZeroAddress(_router);
    USDCAddress.approve(_router, type(uint256).max);
  }

  function withdrawERC20(
    address _tokenAddress,
    address _to,
    uint256 _amount
  ) external onlyIMPTRole(LibIMPT.IMPT_ADMIN_ROLE, AccessManager) {
    TransferHelper.safeTransfer(_tokenAddress, _to, _amount);
  }
}

File 2 of 44 : draft-IERC1822Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (interfaces/draft-IERC1822.sol)

pragma solidity ^0.8.0;

/**
 * @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified
 * proxy whose upgrades are fully controlled by the current implementation.
 */
interface IERC1822ProxiableUpgradeable {
    /**
     * @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation
     * address.
     *
     * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
     * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
     * function revert if invoked through a proxy.
     */
    function proxiableUUID() external view returns (bytes32);
}

File 3 of 44 : IERC1967Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC1967.sol)

pragma solidity ^0.8.0;

/**
 * @dev ERC-1967: Proxy Storage Slots. This interface contains the events defined in the ERC.
 *
 * _Available since v4.8.3._
 */
interface IERC1967Upgradeable {
    /**
     * @dev Emitted when the implementation is upgraded.
     */
    event Upgraded(address indexed implementation);

    /**
     * @dev Emitted when the admin account has changed.
     */
    event AdminChanged(address previousAdmin, address newAdmin);

    /**
     * @dev Emitted when the beacon is changed.
     */
    event BeaconUpgraded(address indexed beacon);
}

File 4 of 44 : IBeaconUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol)

pragma solidity ^0.8.0;

/**
 * @dev This is the interface that {BeaconProxy} expects of its beacon.
 */
interface IBeaconUpgradeable {
    /**
     * @dev Must return an address that can be used as a delegate call target.
     *
     * {BeaconProxy} will check that this address is a contract.
     */
    function implementation() external view returns (address);
}

File 5 of 44 : ERC1967UpgradeUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/ERC1967/ERC1967Upgrade.sol)

pragma solidity ^0.8.2;

import "../beacon/IBeaconUpgradeable.sol";
import "../../interfaces/IERC1967Upgradeable.sol";
import "../../interfaces/draft-IERC1822Upgradeable.sol";
import "../../utils/AddressUpgradeable.sol";
import "../../utils/StorageSlotUpgradeable.sol";
import "../utils/Initializable.sol";

/**
 * @dev This abstract contract provides getters and event emitting update functions for
 * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.
 *
 * _Available since v4.1._
 */
abstract contract ERC1967UpgradeUpgradeable is Initializable, IERC1967Upgradeable {
    function __ERC1967Upgrade_init() internal onlyInitializing {
    }

    function __ERC1967Upgrade_init_unchained() internal onlyInitializing {
    }
    // This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1
    bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143;

    /**
     * @dev Storage slot with the address of the current implementation.
     * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is
     * validated in the constructor.
     */
    bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;

    /**
     * @dev Returns the current implementation address.
     */
    function _getImplementation() internal view returns (address) {
        return StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value;
    }

    /**
     * @dev Stores a new address in the EIP1967 implementation slot.
     */
    function _setImplementation(address newImplementation) private {
        require(AddressUpgradeable.isContract(newImplementation), "ERC1967: new implementation is not a contract");
        StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
    }

    /**
     * @dev Perform implementation upgrade
     *
     * Emits an {Upgraded} event.
     */
    function _upgradeTo(address newImplementation) internal {
        _setImplementation(newImplementation);
        emit Upgraded(newImplementation);
    }

    /**
     * @dev Perform implementation upgrade with additional setup call.
     *
     * Emits an {Upgraded} event.
     */
    function _upgradeToAndCall(address newImplementation, bytes memory data, bool forceCall) internal {
        _upgradeTo(newImplementation);
        if (data.length > 0 || forceCall) {
            AddressUpgradeable.functionDelegateCall(newImplementation, data);
        }
    }

    /**
     * @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call.
     *
     * Emits an {Upgraded} event.
     */
    function _upgradeToAndCallUUPS(address newImplementation, bytes memory data, bool forceCall) internal {
        // Upgrades from old implementations will perform a rollback test. This test requires the new
        // implementation to upgrade back to the old, non-ERC1822 compliant, implementation. Removing
        // this special case will break upgrade paths from old UUPS implementation to new ones.
        if (StorageSlotUpgradeable.getBooleanSlot(_ROLLBACK_SLOT).value) {
            _setImplementation(newImplementation);
        } else {
            try IERC1822ProxiableUpgradeable(newImplementation).proxiableUUID() returns (bytes32 slot) {
                require(slot == _IMPLEMENTATION_SLOT, "ERC1967Upgrade: unsupported proxiableUUID");
            } catch {
                revert("ERC1967Upgrade: new implementation is not UUPS");
            }
            _upgradeToAndCall(newImplementation, data, forceCall);
        }
    }

    /**
     * @dev Storage slot with the admin of the contract.
     * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is
     * validated in the constructor.
     */
    bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;

    /**
     * @dev Returns the current admin.
     */
    function _getAdmin() internal view returns (address) {
        return StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value;
    }

    /**
     * @dev Stores a new address in the EIP1967 admin slot.
     */
    function _setAdmin(address newAdmin) private {
        require(newAdmin != address(0), "ERC1967: new admin is the zero address");
        StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value = newAdmin;
    }

    /**
     * @dev Changes the admin of the proxy.
     *
     * Emits an {AdminChanged} event.
     */
    function _changeAdmin(address newAdmin) internal {
        emit AdminChanged(_getAdmin(), newAdmin);
        _setAdmin(newAdmin);
    }

    /**
     * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
     * This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor.
     */
    bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;

    /**
     * @dev Returns the current beacon.
     */
    function _getBeacon() internal view returns (address) {
        return StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value;
    }

    /**
     * @dev Stores a new beacon in the EIP1967 beacon slot.
     */
    function _setBeacon(address newBeacon) private {
        require(AddressUpgradeable.isContract(newBeacon), "ERC1967: new beacon is not a contract");
        require(
            AddressUpgradeable.isContract(IBeaconUpgradeable(newBeacon).implementation()),
            "ERC1967: beacon implementation is not a contract"
        );
        StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value = newBeacon;
    }

    /**
     * @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does
     * not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that).
     *
     * Emits a {BeaconUpgraded} event.
     */
    function _upgradeBeaconToAndCall(address newBeacon, bytes memory data, bool forceCall) internal {
        _setBeacon(newBeacon);
        emit BeaconUpgraded(newBeacon);
        if (data.length > 0 || forceCall) {
            AddressUpgradeable.functionDelegateCall(IBeaconUpgradeable(newBeacon).implementation(), data);
        }
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[50] private __gap;
}

File 6 of 44 : Initializable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.2;

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

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
 * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
 * case an upgrade adds a module that needs to be initialized.
 *
 * For example:
 *
 * [.hljs-theme-light.nopadding]
 * ```solidity
 * contract MyToken is ERC20Upgradeable {
 *     function initialize() initializer public {
 *         __ERC20_init("MyToken", "MTK");
 *     }
 * }
 *
 * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
 *     function initializeV2() reinitializer(2) public {
 *         __ERC20Permit_init("MyToken");
 *     }
 * }
 * ```
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 *
 * [CAUTION]
 * ====
 * Avoid leaving a contract uninitialized.
 *
 * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
 * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
 * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() {
 *     _disableInitializers();
 * }
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Indicates that the contract has been initialized.
     * @custom:oz-retyped-from bool
     */
    uint8 private _initialized;

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

    /**
     * @dev Triggered when the contract has been initialized or reinitialized.
     */
    event Initialized(uint8 version);

    /**
     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
     * `onlyInitializing` functions can be used to initialize parent contracts.
     *
     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a
     * constructor.
     *
     * Emits an {Initialized} event.
     */
    modifier initializer() {
        bool isTopLevelCall = !_initializing;
        require(
            (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
            "Initializable: contract is already initialized"
        );
        _initialized = 1;
        if (isTopLevelCall) {
            _initializing = true;
        }
        _;
        if (isTopLevelCall) {
            _initializing = false;
            emit Initialized(1);
        }
    }

    /**
     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
     * used to initialize parent contracts.
     *
     * A reinitializer may be used after the original initialization step. This is essential to configure modules that
     * are added through upgrades and that require initialization.
     *
     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
     * cannot be nested. If one is invoked in the context of another, execution will revert.
     *
     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
     * a contract, executing them in the right order is up to the developer or operator.
     *
     * WARNING: setting the version to 255 will prevent any future reinitialization.
     *
     * Emits an {Initialized} event.
     */
    modifier reinitializer(uint8 version) {
        require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
        _initialized = version;
        _initializing = true;
        _;
        _initializing = false;
        emit Initialized(version);
    }

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

    /**
     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called
     * through proxies.
     *
     * Emits an {Initialized} event the first time it is successfully executed.
     */
    function _disableInitializers() internal virtual {
        require(!_initializing, "Initializable: contract is initializing");
        if (_initialized != type(uint8).max) {
            _initialized = type(uint8).max;
            emit Initialized(type(uint8).max);
        }
    }

    /**
     * @dev Returns the highest version that has been initialized. See {reinitializer}.
     */
    function _getInitializedVersion() internal view returns (uint8) {
        return _initialized;
    }

    /**
     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
     */
    function _isInitializing() internal view returns (bool) {
        return _initializing;
    }
}

File 7 of 44 : UUPSUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/UUPSUpgradeable.sol)

pragma solidity ^0.8.0;

import "../../interfaces/draft-IERC1822Upgradeable.sol";
import "../ERC1967/ERC1967UpgradeUpgradeable.sol";
import "./Initializable.sol";

/**
 * @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an
 * {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.
 *
 * A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is
 * reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing
 * `UUPSUpgradeable` with a custom implementation of upgrades.
 *
 * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.
 *
 * _Available since v4.1._
 */
abstract contract UUPSUpgradeable is Initializable, IERC1822ProxiableUpgradeable, ERC1967UpgradeUpgradeable {
    function __UUPSUpgradeable_init() internal onlyInitializing {
    }

    function __UUPSUpgradeable_init_unchained() internal onlyInitializing {
    }
    /// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment
    address private immutable __self = address(this);

    /**
     * @dev Check that the execution is being performed through a delegatecall call and that the execution context is
     * a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case
     * for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a
     * function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to
     * fail.
     */
    modifier onlyProxy() {
        require(address(this) != __self, "Function must be called through delegatecall");
        require(_getImplementation() == __self, "Function must be called through active proxy");
        _;
    }

    /**
     * @dev Check that the execution is not being performed through a delegate call. This allows a function to be
     * callable on the implementing contract but not through proxies.
     */
    modifier notDelegated() {
        require(address(this) == __self, "UUPSUpgradeable: must not be called through delegatecall");
        _;
    }

    /**
     * @dev Implementation of the ERC1822 {proxiableUUID} function. This returns the storage slot used by the
     * implementation. It is used to validate the implementation's compatibility when performing an upgrade.
     *
     * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
     * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
     * function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.
     */
    function proxiableUUID() external view virtual override notDelegated returns (bytes32) {
        return _IMPLEMENTATION_SLOT;
    }

    /**
     * @dev Upgrade the implementation of the proxy to `newImplementation`.
     *
     * Calls {_authorizeUpgrade}.
     *
     * Emits an {Upgraded} event.
     *
     * @custom:oz-upgrades-unsafe-allow-reachable delegatecall
     */
    function upgradeTo(address newImplementation) public virtual onlyProxy {
        _authorizeUpgrade(newImplementation);
        _upgradeToAndCallUUPS(newImplementation, new bytes(0), false);
    }

    /**
     * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
     * encoded in `data`.
     *
     * Calls {_authorizeUpgrade}.
     *
     * Emits an {Upgraded} event.
     *
     * @custom:oz-upgrades-unsafe-allow-reachable delegatecall
     */
    function upgradeToAndCall(address newImplementation, bytes memory data) public payable virtual onlyProxy {
        _authorizeUpgrade(newImplementation);
        _upgradeToAndCallUUPS(newImplementation, data, true);
    }

    /**
     * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by
     * {upgradeTo} and {upgradeToAndCall}.
     *
     * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.
     *
     * ```solidity
     * function _authorizeUpgrade(address) internal override onlyOwner {}
     * ```
     */
    function _authorizeUpgrade(address newImplementation) internal virtual;

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[50] private __gap;
}

File 8 of 44 : PausableUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)

pragma solidity ^0.8.0;

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

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

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

    bool private _paused;

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

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

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

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

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

    /**
     * @dev Throws if the contract is paused.
     */
    function _requireNotPaused() internal view virtual {
        require(!paused(), "Pausable: paused");
    }

    /**
     * @dev Throws if the contract is not paused.
     */
    function _requirePaused() internal view virtual {
        require(paused(), "Pausable: not paused");
    }

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

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

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[49] private __gap;
}

File 9 of 44 : ERC1155Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC1155/ERC1155.sol)

pragma solidity ^0.8.0;

import "./IERC1155Upgradeable.sol";
import "./IERC1155ReceiverUpgradeable.sol";
import "./extensions/IERC1155MetadataURIUpgradeable.sol";
import "../../utils/AddressUpgradeable.sol";
import "../../utils/ContextUpgradeable.sol";
import "../../utils/introspection/ERC165Upgradeable.sol";
import "../../proxy/utils/Initializable.sol";

/**
 * @dev Implementation of the basic standard multi-token.
 * See https://eips.ethereum.org/EIPS/eip-1155
 * Originally based on code by Enjin: https://github.com/enjin/erc-1155
 *
 * _Available since v3.1._
 */
contract ERC1155Upgradeable is Initializable, ContextUpgradeable, ERC165Upgradeable, IERC1155Upgradeable, IERC1155MetadataURIUpgradeable {
    using AddressUpgradeable for address;

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

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

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

    /**
     * @dev See {_setURI}.
     */
    function __ERC1155_init(string memory uri_) internal onlyInitializing {
        __ERC1155_init_unchained(uri_);
    }

    function __ERC1155_init_unchained(string memory uri_) internal onlyInitializing {
        _setURI(uri_);
    }

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165Upgradeable, IERC165Upgradeable) returns (bool) {
        return
            interfaceId == type(IERC1155Upgradeable).interfaceId ||
            interfaceId == type(IERC1155MetadataURIUpgradeable).interfaceId ||
            super.supportsInterface(interfaceId);
    }

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

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

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

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

        for (uint256 i = 0; i < accounts.length; ++i) {
            batchBalances[i] = balanceOf(accounts[i], ids[i]);
        }

        return batchBalances;
    }

    /**
     * @dev See {IERC1155-setApprovalForAll}.
     */
    function setApprovalForAll(address operator, bool approved) public virtual override {
        _setApprovalForAll(_msgSender(), operator, approved);
    }

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

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

    /**
     * @dev See {IERC1155-safeBatchTransferFrom}.
     */
    function safeBatchTransferFrom(
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) public virtual override {
        require(
            from == _msgSender() || isApprovedForAll(from, _msgSender()),
            "ERC1155: caller is not token owner or approved"
        );
        _safeBatchTransferFrom(from, to, ids, amounts, data);
    }

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

        address operator = _msgSender();
        uint256[] memory ids = _asSingletonArray(id);
        uint256[] memory amounts = _asSingletonArray(amount);

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

        uint256 fromBalance = _balances[id][from];
        require(fromBalance >= amount, "ERC1155: insufficient balance for transfer");
        unchecked {
            _balances[id][from] = fromBalance - amount;
        }
        _balances[id][to] += amount;

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

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

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

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_safeTransferFrom}.
     *
     * Emits a {TransferBatch} event.
     *
     * Requirements:
     *
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
     * acceptance magic value.
     */
    function _safeBatchTransferFrom(
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) internal virtual {
        require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
        require(to != address(0), "ERC1155: transfer to the zero address");

        address operator = _msgSender();

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

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

            uint256 fromBalance = _balances[id][from];
            require(fromBalance >= amount, "ERC1155: insufficient balance for transfer");
            unchecked {
                _balances[id][from] = fromBalance - amount;
            }
            _balances[id][to] += amount;
        }

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

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

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

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

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

        address operator = _msgSender();
        uint256[] memory ids = _asSingletonArray(id);
        uint256[] memory amounts = _asSingletonArray(amount);

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

        _balances[id][to] += amount;
        emit TransferSingle(operator, address(0), to, id, amount);

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

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

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_mint}.
     *
     * Emits a {TransferBatch} event.
     *
     * Requirements:
     *
     * - `ids` and `amounts` must have the same length.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
     * acceptance magic value.
     */
    function _mintBatch(
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) internal virtual {
        require(to != address(0), "ERC1155: mint to the zero address");
        require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");

        address operator = _msgSender();

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

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

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

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

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

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

        address operator = _msgSender();
        uint256[] memory ids = _asSingletonArray(id);
        uint256[] memory amounts = _asSingletonArray(amount);

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

        uint256 fromBalance = _balances[id][from];
        require(fromBalance >= amount, "ERC1155: burn amount exceeds balance");
        unchecked {
            _balances[id][from] = fromBalance - amount;
        }

        emit TransferSingle(operator, from, address(0), id, amount);

        _afterTokenTransfer(operator, from, address(0), ids, amounts, "");
    }

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

        address operator = _msgSender();

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

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

            uint256 fromBalance = _balances[id][from];
            require(fromBalance >= amount, "ERC1155: burn amount exceeds balance");
            unchecked {
                _balances[id][from] = fromBalance - amount;
            }
        }

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

        _afterTokenTransfer(operator, from, address(0), ids, amounts, "");
    }

    /**
     * @dev Approve `operator` to operate on all of `owner` tokens
     *
     * Emits an {ApprovalForAll} event.
     */
    function _setApprovalForAll(address owner, address operator, bool approved) internal virtual {
        require(owner != operator, "ERC1155: setting approval status for self");
        _operatorApprovals[owner][operator] = approved;
        emit ApprovalForAll(owner, operator, approved);
    }

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

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

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

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

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

        return array;
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[47] private __gap;
}

File 10 of 44 : IERC1155MetadataURIUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC1155/extensions/IERC1155MetadataURI.sol)

pragma solidity ^0.8.0;

import "../IERC1155Upgradeable.sol";

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

File 11 of 44 : IERC1155ReceiverUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC1155/IERC1155Receiver.sol)

pragma solidity ^0.8.0;

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

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

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

File 12 of 44 : IERC1155Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC1155/IERC1155.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

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

File 13 of 44 : ERC20Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/ERC20.sol)

pragma solidity ^0.8.0;

import "./IERC20Upgradeable.sol";
import "./extensions/IERC20MetadataUpgradeable.sol";
import "../../utils/ContextUpgradeable.sol";
import "../../proxy/utils/Initializable.sol";

/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 * For a generic mechanism see {ERC20PresetMinterPauser}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * The default value of {decimals} is 18. To change this, you should override
 * this function so it returns a different value.
 *
 * We have followed general OpenZeppelin Contracts guidelines: functions revert
 * instead returning `false` on failure. This behavior is nonetheless
 * conventional and does not conflict with the expectations of ERC20
 * applications.
 *
 * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
 * This allows applications to reconstruct the allowance for all accounts just
 * by listening to said events. Other implementations of the EIP may not emit
 * these events, as it isn't required by the specification.
 *
 * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
 * functions have been added to mitigate the well-known issues around setting
 * allowances. See {IERC20-approve}.
 */
contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable, IERC20MetadataUpgradeable {
    mapping(address => uint256) private _balances;

    mapping(address => mapping(address => uint256)) private _allowances;

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * All two of these values are immutable: they can only be set once during
     * construction.
     */
    function __ERC20_init(string memory name_, string memory symbol_) internal onlyInitializing {
        __ERC20_init_unchained(name_, symbol_);
    }

    function __ERC20_init_unchained(string memory name_, string memory symbol_) internal onlyInitializing {
        _name = name_;
        _symbol = symbol_;
    }

    /**
     * @dev Returns the name of the token.
     */
    function name() public view virtual override returns (string memory) {
        return _name;
    }

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view virtual override returns (string memory) {
        return _symbol;
    }

    /**
     * @dev Returns the number of decimals used to get its user representation.
     * For example, if `decimals` equals `2`, a balance of `505` tokens should
     * be displayed to a user as `5.05` (`505 / 10 ** 2`).
     *
     * Tokens usually opt for a value of 18, imitating the relationship between
     * Ether and Wei. This is the default value returned by this function, unless
     * it's overridden.
     *
     * NOTE: This information is only used for _display_ purposes: it in
     * no way affects any of the arithmetic of the contract, including
     * {IERC20-balanceOf} and {IERC20-transfer}.
     */
    function decimals() public view virtual override returns (uint8) {
        return 18;
    }

    /**
     * @dev See {IERC20-totalSupply}.
     */
    function totalSupply() public view virtual override returns (uint256) {
        return _totalSupply;
    }

    /**
     * @dev See {IERC20-balanceOf}.
     */
    function balanceOf(address account) public view virtual override returns (uint256) {
        return _balances[account];
    }

    /**
     * @dev See {IERC20-transfer}.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - the caller must have a balance of at least `amount`.
     */
    function transfer(address to, uint256 amount) public virtual override returns (bool) {
        address owner = _msgSender();
        _transfer(owner, to, amount);
        return true;
    }

    /**
     * @dev See {IERC20-allowance}.
     */
    function allowance(address owner, address spender) public view virtual override returns (uint256) {
        return _allowances[owner][spender];
    }

    /**
     * @dev See {IERC20-approve}.
     *
     * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
     * `transferFrom`. This is semantically equivalent to an infinite approval.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, amount);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Emits an {Approval} event indicating the updated allowance. This is not
     * required by the EIP. See the note at the beginning of {ERC20}.
     *
     * NOTE: Does not update the allowance if the current allowance
     * is the maximum `uint256`.
     *
     * Requirements:
     *
     * - `from` and `to` cannot be the zero address.
     * - `from` must have a balance of at least `amount`.
     * - the caller must have allowance for ``from``'s tokens of at least
     * `amount`.
     */
    function transferFrom(address from, address to, uint256 amount) public virtual override returns (bool) {
        address spender = _msgSender();
        _spendAllowance(from, spender, amount);
        _transfer(from, to, amount);
        return true;
    }

    /**
     * @dev Atomically increases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, allowance(owner, spender) + addedValue);
        return true;
    }

    /**
     * @dev Atomically decreases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `spender` must have allowance for the caller of at least
     * `subtractedValue`.
     */
    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
        address owner = _msgSender();
        uint256 currentAllowance = allowance(owner, spender);
        require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
        unchecked {
            _approve(owner, spender, currentAllowance - subtractedValue);
        }

        return true;
    }

    /**
     * @dev Moves `amount` of tokens from `from` to `to`.
     *
     * This internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `from` must have a balance of at least `amount`.
     */
    function _transfer(address from, address to, uint256 amount) internal virtual {
        require(from != address(0), "ERC20: transfer from the zero address");
        require(to != address(0), "ERC20: transfer to the zero address");

        _beforeTokenTransfer(from, to, amount);

        uint256 fromBalance = _balances[from];
        require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
        unchecked {
            _balances[from] = fromBalance - amount;
            // Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by
            // decrementing then incrementing.
            _balances[to] += amount;
        }

        emit Transfer(from, to, amount);

        _afterTokenTransfer(from, to, amount);
    }

    /** @dev Creates `amount` tokens and assigns them to `account`, increasing
     * the total supply.
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     */
    function _mint(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: mint to the zero address");

        _beforeTokenTransfer(address(0), account, amount);

        _totalSupply += amount;
        unchecked {
            // Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.
            _balances[account] += amount;
        }
        emit Transfer(address(0), account, amount);

        _afterTokenTransfer(address(0), account, amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, reducing the
     * total supply.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     * - `account` must have at least `amount` tokens.
     */
    function _burn(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: burn from the zero address");

        _beforeTokenTransfer(account, address(0), amount);

        uint256 accountBalance = _balances[account];
        require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
        unchecked {
            _balances[account] = accountBalance - amount;
            // Overflow not possible: amount <= accountBalance <= totalSupply.
            _totalSupply -= amount;
        }

        emit Transfer(account, address(0), amount);

        _afterTokenTransfer(account, address(0), amount);
    }

    /**
     * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     */
    function _approve(address owner, address spender, uint256 amount) internal virtual {
        require(owner != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");

        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }

    /**
     * @dev Updates `owner` s allowance for `spender` based on spent `amount`.
     *
     * Does not update the allowance amount in case of infinite allowance.
     * Revert if not enough allowance is available.
     *
     * Might emit an {Approval} event.
     */
    function _spendAllowance(address owner, address spender, uint256 amount) internal virtual {
        uint256 currentAllowance = allowance(owner, spender);
        if (currentAllowance != type(uint256).max) {
            require(currentAllowance >= amount, "ERC20: insufficient allowance");
            unchecked {
                _approve(owner, spender, currentAllowance - amount);
            }
        }
    }

    /**
     * @dev Hook that is called before any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * will be transferred to `to`.
     * - when `from` is zero, `amount` tokens will be minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens will be burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual {}

    /**
     * @dev Hook that is called after any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * has been transferred to `to`.
     * - when `from` is zero, `amount` tokens have been minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens have been burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _afterTokenTransfer(address from, address to, uint256 amount) internal virtual {}

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[45] private __gap;
}

File 14 of 44 : ERC20BurnableUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/extensions/ERC20Burnable.sol)

pragma solidity ^0.8.0;

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

/**
 * @dev Extension of {ERC20} that allows token holders to destroy both their own
 * tokens and those that they have an allowance for, in a way that can be
 * recognized off-chain (via event analysis).
 */
abstract contract ERC20BurnableUpgradeable is Initializable, ContextUpgradeable, ERC20Upgradeable {
    function __ERC20Burnable_init() internal onlyInitializing {
    }

    function __ERC20Burnable_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev Destroys `amount` tokens from the caller.
     *
     * See {ERC20-_burn}.
     */
    function burn(uint256 amount) public virtual {
        _burn(_msgSender(), amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, deducting from the caller's
     * allowance.
     *
     * See {ERC20-_burn} and {ERC20-allowance}.
     *
     * Requirements:
     *
     * - the caller must have allowance for ``accounts``'s tokens of at least
     * `amount`.
     */
    function burnFrom(address account, uint256 amount) public virtual {
        _spendAllowance(account, _msgSender(), amount);
        _burn(account, amount);
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[50] private __gap;
}

File 15 of 44 : IERC20MetadataUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.0;

import "../IERC20Upgradeable.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 *
 * _Available since v4.1._
 */
interface IERC20MetadataUpgradeable is IERC20Upgradeable {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

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

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}

File 16 of 44 : IERC20PermitUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/IERC20Permit.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 */
interface IERC20PermitUpgradeable {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    /**
     * @dev Returns the current nonce for `owner`. This value must be
     * included whenever a signature is generated for {permit}.
     *
     * Every successful call to {permit} increases ``owner``'s nonce by one. This
     * prevents a signature from being used multiple times.
     */
    function nonces(address owner) external view returns (uint256);

    /**
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}

File 17 of 44 : IERC20Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20Upgradeable {
    /**
     * @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);

    /**
     * @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 `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, 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 `from` to `to` 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 from, address to, uint256 amount) external returns (bool);
}

File 18 of 44 : SafeERC20Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20Upgradeable.sol";
import "../extensions/IERC20PermitUpgradeable.sol";
import "../../../utils/AddressUpgradeable.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 SafeERC20Upgradeable {
    using AddressUpgradeable for address;

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20Upgradeable token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    function safeTransferFrom(IERC20Upgradeable 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(IERC20Upgradeable 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'
        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));
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeIncreaseAllowance(IERC20Upgradeable token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeDecreaseAllowance(IERC20Upgradeable token, address spender, uint256 value) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
     * to be set to zero before setting it to a non-zero value, such as USDT.
     */
    function forceApprove(IERC20Upgradeable token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);

        if (!_callOptionalReturnBool(token, approvalCall)) {
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
            _callOptionalReturn(token, approvalCall);
        }
    }

    /**
     * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
     * Revert on invalid signature.
     */
    function safePermit(
        IERC20PermitUpgradeable token,
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        uint256 nonceBefore = token.nonces(owner);
        token.permit(owner, spender, value, deadline, v, r, s);
        uint256 nonceAfter = token.nonces(owner);
        require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
    }

    /**
     * @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(IERC20Upgradeable 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");
        require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
    }

    /**
     * @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).
     *
     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20Upgradeable token, bytes memory data) private returns (bool) {
        // 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 cannot use {Address-functionCall} here since this should return false
        // and not revert is the subcall reverts.

        (bool success, bytes memory returndata) = address(token).call(data);
        return
            success && (returndata.length == 0 || abi.decode(returndata, (bool))) && AddressUpgradeable.isContract(address(token));
    }
}

File 19 of 44 : AddressUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library AddressUpgradeable {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     *
     * Furthermore, `isContract` will also return true if the target contract within
     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
     * which only has an effect at the end of a transaction.
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://consensys.net/diligence/blog/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.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

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

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

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    function _revert(bytes memory returndata, string memory errorMessage) private pure {
        // 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
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert(errorMessage);
        }
    }
}

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

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

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

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

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[50] private __gap;
}

File 21 of 44 : ECDSAUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/cryptography/ECDSA.sol)

pragma solidity ^0.8.0;

import "../StringsUpgradeable.sol";

/**
 * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
 *
 * These functions can be used to verify that a message was signed by the holder
 * of the private keys of a given address.
 */
library ECDSAUpgradeable {
    enum RecoverError {
        NoError,
        InvalidSignature,
        InvalidSignatureLength,
        InvalidSignatureS,
        InvalidSignatureV // Deprecated in v4.8
    }

    function _throwError(RecoverError error) private pure {
        if (error == RecoverError.NoError) {
            return; // no error: do nothing
        } else if (error == RecoverError.InvalidSignature) {
            revert("ECDSA: invalid signature");
        } else if (error == RecoverError.InvalidSignatureLength) {
            revert("ECDSA: invalid signature length");
        } else if (error == RecoverError.InvalidSignatureS) {
            revert("ECDSA: invalid signature 's' value");
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature` or error string. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {toEthSignedMessageHash} on it.
     *
     * Documentation for signature generation:
     * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
     * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
     *
     * _Available since v4.3._
     */
    function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
        if (signature.length == 65) {
            bytes32 r;
            bytes32 s;
            uint8 v;
            // ecrecover takes the signature parameters, and the only way to get them
            // currently is to use assembly.
            /// @solidity memory-safe-assembly
            assembly {
                r := mload(add(signature, 0x20))
                s := mload(add(signature, 0x40))
                v := byte(0, mload(add(signature, 0x60)))
            }
            return tryRecover(hash, v, r, s);
        } else {
            return (address(0), RecoverError.InvalidSignatureLength);
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature`. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {toEthSignedMessageHash} on it.
     */
    function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, signature);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
     *
     * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
     *
     * _Available since v4.3._
     */
    function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError) {
        bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
        uint8 v = uint8((uint256(vs) >> 255) + 27);
        return tryRecover(hash, v, r, s);
    }

    /**
     * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
     *
     * _Available since v4.2._
     */
    function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, r, vs);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `v`,
     * `r` and `s` signature fields separately.
     *
     * _Available since v4.3._
     */
    function tryRecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address, RecoverError) {
        // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
        // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
        // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
        // signatures from current libraries generate a unique signature with an s-value in the lower half order.
        //
        // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
        // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
        // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
        // these malleable signatures as well.
        if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
            return (address(0), RecoverError.InvalidSignatureS);
        }

        // If the signature is valid (and not malleable), return the signer address
        address signer = ecrecover(hash, v, r, s);
        if (signer == address(0)) {
            return (address(0), RecoverError.InvalidSignature);
        }

        return (signer, RecoverError.NoError);
    }

    /**
     * @dev Overload of {ECDSA-recover} that receives the `v`,
     * `r` and `s` signature fields separately.
     */
    function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, v, r, s);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Returns an Ethereum Signed Message, created from a `hash`. This
     * produces hash corresponding to the one signed with the
     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
     * JSON-RPC method as part of EIP-191.
     *
     * See {recover}.
     */
    function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32 message) {
        // 32 is the length in bytes of hash,
        // enforced by the type signature above
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x00, "\x19Ethereum Signed Message:\n32")
            mstore(0x1c, hash)
            message := keccak256(0x00, 0x3c)
        }
    }

    /**
     * @dev Returns an Ethereum Signed Message, created from `s`. This
     * produces hash corresponding to the one signed with the
     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
     * JSON-RPC method as part of EIP-191.
     *
     * See {recover}.
     */
    function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", StringsUpgradeable.toString(s.length), s));
    }

    /**
     * @dev Returns an Ethereum Signed Typed Data, created from a
     * `domainSeparator` and a `structHash`. This produces hash corresponding
     * to the one signed with the
     * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
     * JSON-RPC method as part of EIP-712.
     *
     * See {recover}.
     */
    function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 data) {
        /// @solidity memory-safe-assembly
        assembly {
            let ptr := mload(0x40)
            mstore(ptr, "\x19\x01")
            mstore(add(ptr, 0x02), domainSeparator)
            mstore(add(ptr, 0x22), structHash)
            data := keccak256(ptr, 0x42)
        }
    }

    /**
     * @dev Returns an Ethereum Signed Data with intended validator, created from a
     * `validator` and `data` according to the version 0 of EIP-191.
     *
     * See {recover}.
     */
    function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked("\x19\x00", validator, data));
    }
}

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

pragma solidity ^0.8.0;

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

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

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

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[50] private __gap;
}

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

pragma solidity ^0.8.0;

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

File 24 of 44 : MathUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)

pragma solidity ^0.8.0;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library MathUpgradeable {
    enum Rounding {
        Down, // Toward negative infinity
        Up, // Toward infinity
        Zero // Toward zero
    }

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

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

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

    /**
     * @dev Returns the ceiling of the division of two numbers.
     *
     * This differs from standard division with `/` in that it rounds up instead
     * of rounding down.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b - 1) / b can overflow on addition, so we distribute.
        return a == 0 ? 0 : (a - 1) / b + 1;
    }

    /**
     * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
     * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
     * with further edits by Uniswap Labs also under MIT license.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
        unchecked {
            // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
            // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
            // variables such that product = prod1 * 2^256 + prod0.
            uint256 prod0; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly {
                let mm := mulmod(x, y, not(0))
                prod0 := mul(x, y)
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

            // Handle non-overflow cases, 256 by 256 division.
            if (prod1 == 0) {
                // Solidity will revert if denominator == 0, unlike the div opcode on its own.
                // The surrounding unchecked block does not change this fact.
                // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
                return prod0 / denominator;
            }

            // Make sure the result is less than 2^256. Also prevents denominator == 0.
            require(denominator > prod1, "Math: mulDiv overflow");

            ///////////////////////////////////////////////
            // 512 by 256 division.
            ///////////////////////////////////////////////

            // Make division exact by subtracting the remainder from [prod1 prod0].
            uint256 remainder;
            assembly {
                // Compute remainder using mulmod.
                remainder := mulmod(x, y, denominator)

                // Subtract 256 bit number from 512 bit number.
                prod1 := sub(prod1, gt(remainder, prod0))
                prod0 := sub(prod0, remainder)
            }

            // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
            // See https://cs.stackexchange.com/q/138556/92363.

            // Does not overflow because the denominator cannot be zero at this stage in the function.
            uint256 twos = denominator & (~denominator + 1);
            assembly {
                // Divide denominator by twos.
                denominator := div(denominator, twos)

                // Divide [prod1 prod0] by twos.
                prod0 := div(prod0, twos)

                // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
                twos := add(div(sub(0, twos), twos), 1)
            }

            // Shift in bits from prod1 into prod0.
            prod0 |= prod1 * twos;

            // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
            // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
            // four bits. That is, denominator * inv = 1 mod 2^4.
            uint256 inverse = (3 * denominator) ^ 2;

            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
            // in modular arithmetic, doubling the correct bits in each step.
            inverse *= 2 - denominator * inverse; // inverse mod 2^8
            inverse *= 2 - denominator * inverse; // inverse mod 2^16
            inverse *= 2 - denominator * inverse; // inverse mod 2^32
            inverse *= 2 - denominator * inverse; // inverse mod 2^64
            inverse *= 2 - denominator * inverse; // inverse mod 2^128
            inverse *= 2 - denominator * inverse; // inverse mod 2^256

            // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
            // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
            // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
            // is no longer required.
            result = prod0 * inverse;
            return result;
        }
    }

    /**
     * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
        uint256 result = mulDiv(x, y, denominator);
        if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
            result += 1;
        }
        return result;
    }

    /**
     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
     *
     * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
     */
    function sqrt(uint256 a) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        }

        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
        //
        // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
        // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
        //
        // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
        // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
        // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
        //
        // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
        uint256 result = 1 << (log2(a) >> 1);

        // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
        // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
        // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
        // into the expected uint128 result.
        unchecked {
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            return min(result, a / result);
        }
    }

    /**
     * @notice Calculates sqrt(a), following the selected rounding direction.
     */
    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = sqrt(a);
            return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 2, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 128;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 64;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 32;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 16;
            }
            if (value >> 8 > 0) {
                value >>= 8;
                result += 8;
            }
            if (value >> 4 > 0) {
                value >>= 4;
                result += 4;
            }
            if (value >> 2 > 0) {
                value >>= 2;
                result += 2;
            }
            if (value >> 1 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log2(value);
            return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 10, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >= 10 ** 64) {
                value /= 10 ** 64;
                result += 64;
            }
            if (value >= 10 ** 32) {
                value /= 10 ** 32;
                result += 32;
            }
            if (value >= 10 ** 16) {
                value /= 10 ** 16;
                result += 16;
            }
            if (value >= 10 ** 8) {
                value /= 10 ** 8;
                result += 8;
            }
            if (value >= 10 ** 4) {
                value /= 10 ** 4;
                result += 4;
            }
            if (value >= 10 ** 2) {
                value /= 10 ** 2;
                result += 2;
            }
            if (value >= 10 ** 1) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log10(value);
            return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 256, rounded down, of a positive value.
     * Returns 0 if given 0.
     *
     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
     */
    function log256(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 16;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 8;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 4;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 2;
            }
            if (value >> 8 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 256, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log256(value);
            return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
        }
    }
}

File 25 of 44 : SignedMathUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol)

pragma solidity ^0.8.0;

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

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

    /**
     * @dev Returns the average of two signed numbers without overflow.
     * The result is rounded towards zero.
     */
    function average(int256 a, int256 b) internal pure returns (int256) {
        // Formula from the book "Hacker's Delight"
        int256 x = (a & b) + ((a ^ b) >> 1);
        return x + (int256(uint256(x) >> 255) & (a ^ b));
    }

    /**
     * @dev Returns the absolute unsigned value of a signed value.
     */
    function abs(int256 n) internal pure returns (uint256) {
        unchecked {
            // must be unchecked in order to support `n = type(int256).min`
            return uint256(n >= 0 ? n : -n);
        }
    }
}

File 26 of 44 : StorageSlotUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.

pragma solidity ^0.8.0;

/**
 * @dev Library for reading and writing primitive types to specific storage slots.
 *
 * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
 * This library helps with reading and writing to such slots without the need for inline assembly.
 *
 * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
 *
 * Example usage to set ERC1967 implementation slot:
 * ```solidity
 * contract ERC1967 {
 *     bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
 *
 *     function _getImplementation() internal view returns (address) {
 *         return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
 *     }
 *
 *     function _setImplementation(address newImplementation) internal {
 *         require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
 *         StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
 *     }
 * }
 * ```
 *
 * _Available since v4.1 for `address`, `bool`, `bytes32`, `uint256`._
 * _Available since v4.9 for `string`, `bytes`._
 */
library StorageSlotUpgradeable {
    struct AddressSlot {
        address value;
    }

    struct BooleanSlot {
        bool value;
    }

    struct Bytes32Slot {
        bytes32 value;
    }

    struct Uint256Slot {
        uint256 value;
    }

    struct StringSlot {
        string value;
    }

    struct BytesSlot {
        bytes value;
    }

    /**
     * @dev Returns an `AddressSlot` with member `value` located at `slot`.
     */
    function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BooleanSlot` with member `value` located at `slot`.
     */
    function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
     */
    function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Uint256Slot` with member `value` located at `slot`.
     */
    function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `StringSlot` with member `value` located at `slot`.
     */
    function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `StringSlot` representation of the string storage pointer `store`.
     */
    function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := store.slot
        }
    }

    /**
     * @dev Returns an `BytesSlot` with member `value` located at `slot`.
     */
    function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
     */
    function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := store.slot
        }
    }
}

File 27 of 44 : StringsUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol)

pragma solidity ^0.8.0;

import "./math/MathUpgradeable.sol";
import "./math/SignedMathUpgradeable.sol";

/**
 * @dev String operations.
 */
library StringsUpgradeable {
    bytes16 private constant _SYMBOLS = "0123456789abcdef";
    uint8 private constant _ADDRESS_LENGTH = 20;

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        unchecked {
            uint256 length = MathUpgradeable.log10(value) + 1;
            string memory buffer = new string(length);
            uint256 ptr;
            /// @solidity memory-safe-assembly
            assembly {
                ptr := add(buffer, add(32, length))
            }
            while (true) {
                ptr--;
                /// @solidity memory-safe-assembly
                assembly {
                    mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
                }
                value /= 10;
                if (value == 0) break;
            }
            return buffer;
        }
    }

    /**
     * @dev Converts a `int256` to its ASCII `string` decimal representation.
     */
    function toString(int256 value) internal pure returns (string memory) {
        return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMathUpgradeable.abs(value))));
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        unchecked {
            return toHexString(value, MathUpgradeable.log256(value) + 1);
        }
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
     */
    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
        bytes memory buffer = new bytes(2 * length + 2);
        buffer[0] = "0";
        buffer[1] = "x";
        for (uint256 i = 2 * length + 1; i > 1; --i) {
            buffer[i] = _SYMBOLS[value & 0xf];
            value >>= 4;
        }
        require(value == 0, "Strings: hex length insufficient");
        return string(buffer);
    }

    /**
     * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
     */
    function toHexString(address addr) internal pure returns (string memory) {
        return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
    }

    /**
     * @dev Returns true if the two strings are equal.
     */
    function equal(string memory a, string memory b) internal pure returns (bool) {
        return keccak256(bytes(a)) == keccak256(bytes(b));
    }
}

File 28 of 44 : IAccessControl.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)

pragma solidity ^0.8.0;

/**
 * @dev External interface of AccessControl declared to support ERC165 detection.
 */
interface IAccessControl {
    /**
     * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
     *
     * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
     * {RoleAdminChanged} not being emitted signaling this.
     *
     * _Available since v3.1._
     */
    event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);

    /**
     * @dev Emitted when `account` is granted `role`.
     *
     * `sender` is the account that originated the contract call, an admin role
     * bearer except when using {AccessControl-_setupRole}.
     */
    event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Emitted when `account` is revoked `role`.
     *
     * `sender` is the account that originated the contract call:
     *   - if using `revokeRole`, it is the admin role bearer
     *   - if using `renounceRole`, it is the role bearer (i.e. `account`)
     */
    event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) external view returns (bool);

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {AccessControl-_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) external view returns (bytes32);

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function grantRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function revokeRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been granted `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `account`.
     */
    function renounceRole(bytes32 role, address account) external;
}

File 29 of 44 : IAccessControlEnumerable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControlEnumerable.sol)

pragma solidity ^0.8.0;

import "./IAccessControl.sol";

/**
 * @dev External interface of AccessControlEnumerable declared to support ERC165 detection.
 */
interface IAccessControlEnumerable is IAccessControl {
    /**
     * @dev Returns one of the accounts that have `role`. `index` must be a
     * value between 0 and {getRoleMemberCount}, non-inclusive.
     *
     * Role bearers are not sorted in any particular way, and their ordering may
     * change at any point.
     *
     * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
     * you perform all queries on the same block. See the following
     * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
     * for more information.
     */
    function getRoleMember(bytes32 role, uint256 index) external view returns (address);

    /**
     * @dev Returns the number of accounts that have `role`. Can be used
     * together with {getRoleMember} to enumerate all bearers of a role.
     */
    function getRoleMemberCount(bytes32 role) external view returns (uint256);
}

File 30 of 44 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @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);

    /**
     * @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 `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, 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 `from` to `to` 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 from, address to, uint256 amount) external returns (bool);
}

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

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface 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 32 of 44 : IUniswapV3SwapCallback.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Callback for IUniswapV3PoolActions#swap
/// @notice Any contract that calls IUniswapV3PoolActions#swap must implement this interface
interface IUniswapV3SwapCallback {
    /// @notice Called to `msg.sender` after executing a swap via IUniswapV3Pool#swap.
    /// @dev In the implementation you must pay the pool tokens owed for the swap.
    /// The caller of this method must be checked to be a UniswapV3Pool deployed by the canonical UniswapV3Factory.
    /// amount0Delta and amount1Delta can both be 0 if no tokens were swapped.
    /// @param amount0Delta The amount of token0 that was sent (negative) or must be received (positive) by the pool by
    /// the end of the swap. If positive, the callback must send that amount of token0 to the pool.
    /// @param amount1Delta The amount of token1 that was sent (negative) or must be received (positive) by the pool by
    /// the end of the swap. If positive, the callback must send that amount of token1 to the pool.
    /// @param data Any data passed through by the caller via the IUniswapV3PoolActions#swap call
    function uniswapV3SwapCallback(
        int256 amount0Delta,
        int256 amount1Delta,
        bytes calldata data
    ) external;
}

File 33 of 44 : ISwapRouter.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
pragma abicoder v2;

import '@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3SwapCallback.sol';

/// @title Router token swapping functionality
/// @notice Functions for swapping tokens via Uniswap V3
interface ISwapRouter is IUniswapV3SwapCallback {
    struct ExactInputSingleParams {
        address tokenIn;
        address tokenOut;
        uint24 fee;
        address recipient;
        uint256 deadline;
        uint256 amountIn;
        uint256 amountOutMinimum;
        uint160 sqrtPriceLimitX96;
    }

    /// @notice Swaps `amountIn` of one token for as much as possible of another token
    /// @param params The parameters necessary for the swap, encoded as `ExactInputSingleParams` in calldata
    /// @return amountOut The amount of the received token
    function exactInputSingle(ExactInputSingleParams calldata params) external payable returns (uint256 amountOut);

    struct ExactInputParams {
        bytes path;
        address recipient;
        uint256 deadline;
        uint256 amountIn;
        uint256 amountOutMinimum;
    }

    /// @notice Swaps `amountIn` of one token for as much as possible of another along the specified path
    /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactInputParams` in calldata
    /// @return amountOut The amount of the received token
    function exactInput(ExactInputParams calldata params) external payable returns (uint256 amountOut);

    struct ExactOutputSingleParams {
        address tokenIn;
        address tokenOut;
        uint24 fee;
        address recipient;
        uint256 deadline;
        uint256 amountOut;
        uint256 amountInMaximum;
        uint160 sqrtPriceLimitX96;
    }

    /// @notice Swaps as little as possible of one token for `amountOut` of another token
    /// @param params The parameters necessary for the swap, encoded as `ExactOutputSingleParams` in calldata
    /// @return amountIn The amount of the input token
    function exactOutputSingle(ExactOutputSingleParams calldata params) external payable returns (uint256 amountIn);

    struct ExactOutputParams {
        bytes path;
        address recipient;
        uint256 deadline;
        uint256 amountOut;
        uint256 amountInMaximum;
    }

    /// @notice Swaps as little as possible of one token for `amountOut` of another along the specified path (reversed)
    /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactOutputParams` in calldata
    /// @return amountIn The amount of the input token
    function exactOutput(ExactOutputParams calldata params) external payable returns (uint256 amountIn);
}

File 34 of 44 : TransferHelper.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.6.0;

import '@openzeppelin/contracts/token/ERC20/IERC20.sol';

library TransferHelper {
    /// @notice Transfers tokens from the targeted address to the given destination
    /// @notice Errors with 'STF' if transfer fails
    /// @param token The contract address of the token to be transferred
    /// @param from The originating address from which the tokens will be transferred
    /// @param to The destination address of the transfer
    /// @param value The amount to be transferred
    function safeTransferFrom(
        address token,
        address from,
        address to,
        uint256 value
    ) internal {
        (bool success, bytes memory data) =
            token.call(abi.encodeWithSelector(IERC20.transferFrom.selector, from, to, value));
        require(success && (data.length == 0 || abi.decode(data, (bool))), 'STF');
    }

    /// @notice Transfers tokens from msg.sender to a recipient
    /// @dev Errors with ST if transfer fails
    /// @param token The contract address of the token which will be transferred
    /// @param to The recipient of the transfer
    /// @param value The value of the transfer
    function safeTransfer(
        address token,
        address to,
        uint256 value
    ) internal {
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.transfer.selector, to, value));
        require(success && (data.length == 0 || abi.decode(data, (bool))), 'ST');
    }

    /// @notice Approves the stipulated contract to spend the given allowance in the given token
    /// @dev Errors with 'SA' if transfer fails
    /// @param token The contract address of the token to be approved
    /// @param to The target of the approval
    /// @param value The amount of the given token the target will be allowed to spend
    function safeApprove(
        address token,
        address to,
        uint256 value
    ) internal {
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.approve.selector, to, value));
        require(success && (data.length == 0 || abi.decode(data, (bool))), 'SA');
    }

    /// @notice Transfers ETH to the recipient address
    /// @dev Fails with `STE`
    /// @param to The destination of the transfer
    /// @param value The value to be transferred
    function safeTransferETH(address to, uint256 value) internal {
        (bool success, ) = to.call{value: value}(new bytes(0));
        require(success, 'STE');
    }
}

File 35 of 44 : CarbonCreditNFT.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.17;

import "@openzeppelin/contracts-upgradeable/token/ERC1155/extensions/IERC1155MetadataURIUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC1155/ERC1155Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";

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

import "./libraries/LibIMPT.sol";
import "./libraries/SigRecovery.sol";

import "../interfaces/ICarbonCreditNFT.sol";
import "../interfaces/ISalesManager.sol";

contract CarbonCreditNFT is
  ICarbonCreditNFT,
  IERC1155MetadataURIUpgradeable,
  ERC1155Upgradeable,
  PausableUpgradeable,
  UUPSUpgradeable
{
  using StringsUpgradeable for uint256;

  IMarketplace public override MarketplaceContract;
  IInventory public override InventoryContract;
  ISoulboundToken public override SoulboundContract;
  IAccessManager public override AccessManager;

  string private _name;
  string private _symbol;

  ISalesManager public SalesManager;

  modifier onlyMarketplace() {
    if (msg.sender != address(MarketplaceContract)) {
      revert TransferMethodDisabled();
    }
    _;
  }

  modifier onlyIMPTRole(bytes32 _role, IAccessManager _AccessManager) {
    LibIMPT._hasIMPTRole(_role, msg.sender, AccessManager);
    _;
  }

  function initialize(ConstructorParams memory _params) public initializer {
    __ERC1155_init(_formatBaseUri(_params.baseURI));
    __Pausable_init();
    __UUPSUpgradeable_init();

    LibIMPT._checkZeroAddress(address(_params.AccessManager));

    AccessManager = _params.AccessManager;

    _name = _params.name;
    _symbol = _params.symbol;
  }

  function name() public view virtual override returns (string memory) {
    return _name;
  }

  function symbol() public view virtual override returns (string memory) {
    return _symbol;
  }

  function uri(
    uint256 _id
  )
    public
    view
    override(
      ICarbonCreditNFT,
      ERC1155Upgradeable,
      IERC1155MetadataURIUpgradeable
    )
    returns (string memory)
  {
    return string.concat(super.uri(_id), "/", _id.toString());
  }

  /// @dev This function is to check that the upgrade functions in UUPSUpgradeable are being called by an address with the correct role
  function _authorizeUpgrade(
    address newImplementation
  ) internal override onlyIMPTRole(LibIMPT.IMPT_ADMIN_ROLE, AccessManager) {}

  function _verifyTransferRequest(
    TransferAuthorisationParams calldata _transferAuthParams,
    bytes calldata _transferAuthSignature
  ) internal view {
    bytes memory encodedTransferRequest = abi.encode(
      _transferAuthParams.expiry,
      _transferAuthParams.to
    );

    address recoveredAddress = SigRecovery.recoverAddressFromMessage(
      encodedTransferRequest,
      _transferAuthSignature
    );

    if (!AccessManager.hasRole(LibIMPT.IMPT_BACKEND_ROLE, recoveredAddress)) {
      revert LibIMPT.InvalidSignature();
    }

    if (_transferAuthParams.expiry < block.timestamp) {
      revert LibIMPT.SignatureExpired();
    }
  }

  function setSalesManager(
    address payable _salesManager
  ) external override onlyIMPTRole(LibIMPT.IMPT_ADMIN_ROLE, AccessManager) {
    LibIMPT._checkZeroAddress(_salesManager);

    SalesManager = ISalesManager(_salesManager);
  }

  function _verifyRetirementSignature(
    RetirementParams calldata _retirementParams
  ) internal view {
    bytes memory encodedRetirementRequest = abi.encode(
      _retirementParams.tokenId,
      _retirementParams.amount,
      _retirementParams.claimPercentage,
      _retirementParams.swapPercentage,
      _retirementParams.usdcSwapAmount,
      _retirementParams.expiry,
      _retirementParams.swapPath
    );

    address recoveredAddress = SigRecovery.recoverAddressFromMessage(
      encodedRetirementRequest,
      _retirementParams.signature
    );

    if (!AccessManager.hasRole(LibIMPT.IMPT_BACKEND_ROLE, recoveredAddress)) {
      revert LibIMPT.InvalidSignature();
    }

    if (_retirementParams.expiry < block.timestamp) {
      revert LibIMPT.SignatureExpired();
    }
  }

  function retire(
    RetirementParams calldata _retirementParams
  ) external override whenNotPaused {
    _verifyRetirementSignature(_retirementParams);
    _burn(msg.sender, _retirementParams.tokenId, _retirementParams.amount);

    // we need to call the sales manager to burn the amount of impt thats locked for this token
    uint256[] memory tokenArray = new uint256[](1);
    tokenArray[0] = _retirementParams.tokenId;
    IInventory.TokenDetails memory tokenDetails = InventoryContract
      .getAllTokenDetails(tokenArray)[0];

    // burn the IMPT that was locked for this token (+ set claimable value for this user burning)
    SalesManager.retireAmount(
      _retirementParams,
      tokenDetails.tokensMinted,
      msg.sender
    );

    // keep track of inventory
    SoulboundContract.incrementRetireCount(
      msg.sender,
      _retirementParams.tokenId,
      _retirementParams.amount
    );
    InventoryContract.incrementBurnCount(
      _retirementParams.tokenId,
      _retirementParams.amount
    );
  }

  /**
   * A function called by the SalesManager bulkPurchaseAndRetire method to retire the tokens that were purchased
   */
  function bulkRetire(
    uint256[] calldata _tokenIds,
    uint256[] calldata _amounts
  ) external whenNotPaused {
    require(
      msg.sender == address(SalesManager),
      "CarbonCreditNFT: Only the SalesManager can call this function"
    );

    for (uint256 i = 0; i < _tokenIds.length; i++) {
      _burn(msg.sender, _tokenIds[i], _amounts[i]);

      // keep track of inventory
      SoulboundContract.incrementRetireCount(
        msg.sender,
        _tokenIds[i],
        _amounts[i]
      );
      InventoryContract.incrementBurnCount(_tokenIds[i], _amounts[i]);
    }
  }

  /// @dev The safeTransferFrom and safeBatchTransferFrom methods are disabled for users, this is because only KYCed user's can hold CarbonCreditNFT's. This KYC status is checked via a centralised backend and a signature is then generated that is validated by the contract. The methods transferFromBackendAuth and batchTransferFromBackendAuth allow this functionality.
  /// @dev Separately the safeTransferFrom and safeBatchTransferFrom are enabled for the MarketplaceContract as that contract will be handling the validation of sale orders and also has it's own checks for the backend signature auth
  function safeTransferFrom(
    address from,
    address to,
    uint256 id,
    uint256 amount,
    bytes memory data
  )
    public
    virtual
    override(ERC1155Upgradeable, IERC1155Upgradeable)
    whenNotPaused
    onlyMarketplace
  {
    super.safeTransferFrom(from, to, id, amount, data);
  }

  function safeBatchTransferFrom(
    address from,
    address to,
    uint256[] memory ids,
    uint256[] memory amounts,
    bytes memory data
  )
    public
    virtual
    override(ERC1155Upgradeable, IERC1155Upgradeable)
    whenNotPaused
    onlyMarketplace
  {
    super.safeBatchTransferFrom(from, to, ids, amounts, data);
  }

  function transferFromBackendAuth(
    address from,
    uint256 id,
    uint256 amount,
    TransferAuthorisationParams calldata transferAuthParams,
    bytes calldata backendSignature
  ) public virtual override whenNotPaused {
    _verifyTransferRequest(transferAuthParams, backendSignature);

    super.safeTransferFrom(from, transferAuthParams.to, id, amount, "");
  }

  function batchTransferFromBackendAuth(
    address from,
    uint256[] memory ids,
    uint256[] memory amounts,
    TransferAuthorisationParams calldata transferAuthParams,
    bytes calldata backendSignature
  ) public virtual override whenNotPaused {
    _verifyTransferRequest(transferAuthParams, backendSignature);

    super.safeBatchTransferFrom(from, transferAuthParams.to, ids, amounts, "");
  }

  function mint(
    address to,
    uint256 id,
    uint256 amount,
    bytes memory data
  )
    external
    virtual
    override
    whenNotPaused
    onlyIMPTRole(LibIMPT.IMPT_MINTER_ROLE, AccessManager)
  {
    InventoryContract.updateTotalMinted(id, amount);
    _mint(to, id, amount, data);
  }

  function mintBatch(
    address to,
    uint256[] memory ids,
    uint256[] memory amounts,
    bytes memory data
  )
    external
    virtual
    override
    whenNotPaused
    onlyIMPTRole(LibIMPT.IMPT_MINTER_ROLE, AccessManager)
  {
    for (uint8 i = 0; i < ids.length; i++) {
      InventoryContract.updateTotalMinted(ids[i], amounts[i]);
    }
    _mintBatch(to, ids, amounts, data);
  }

  /// @dev Concats the provided baseUri with the address of the contract in the following form: `${baseURL}/${address(this)}`
  /// @param _baseUri The base uri to use
  /// @return formattedBaseUri The formatted base uri
  function _formatBaseUri(
    string memory _baseUri
  ) internal view returns (string memory formattedBaseUri) {
    formattedBaseUri = string.concat(
      _baseUri,
      "/",
      StringsUpgradeable.toHexString(uint256(uint160(address(this))), 20)
    );
  }

  function setBaseUri(
    string calldata _baseUri
  ) external override onlyIMPTRole(LibIMPT.DEFAULT_ADMIN_ROLE, AccessManager) {
    string memory formattedBaseUri = _formatBaseUri(_baseUri);
    // Set the URI on the base ERC1155 contract and pull it from there using the uri() method when needed
    super._setURI(formattedBaseUri);

    emit BaseUriUpdated(formattedBaseUri);
  }

  function setMarketplaceContract(
    IMarketplace _marketplaceContract
  ) external override onlyIMPTRole(LibIMPT.IMPT_ADMIN_ROLE, AccessManager) {
    LibIMPT._checkZeroAddress(address(_marketplaceContract));

    MarketplaceContract = _marketplaceContract;

    emit MarketplaceContractChanged(_marketplaceContract);
  }

  function setSoulboundContract(
    ISoulboundToken _soulboundContract
  ) public override onlyIMPTRole(LibIMPT.IMPT_ADMIN_ROLE, AccessManager) {
    LibIMPT._checkZeroAddress(address(_soulboundContract));

    SoulboundContract = _soulboundContract;

    emit SoulboundContractChanged(_soulboundContract);
  }

  function setInventoryContract(
    IInventory _inventoryContract
  ) external override onlyIMPTRole(LibIMPT.IMPT_ADMIN_ROLE, AccessManager) {
    LibIMPT._checkZeroAddress(address(_inventoryContract));

    InventoryContract = _inventoryContract;

    emit InventoryContractChanged(_inventoryContract);
  }

  function pause()
    external
    override
    onlyIMPTRole(LibIMPT.IMPT_ADMIN_ROLE, AccessManager)
  {
    _pause();
  }

  function unpause()
    external
    override
    onlyIMPTRole(LibIMPT.IMPT_ADMIN_ROLE, AccessManager)
  {
    _unpause();
  }

  function isApprovedForAll(
    address _owner,
    address _operator
  )
    public
    view
    override(ERC1155Upgradeable, IERC1155Upgradeable)
    returns (bool isOperator)
  {
    // This allows the marketplace contract to manage user's NFTs during sales without users having to approve their NFTs to the marketplace contract
    if (msg.sender == address(MarketplaceContract)) {
      return true;
    }

    // otherwise, use the default ERC1155.isApprovedForAll()
    return ERC1155Upgradeable.isApprovedForAll(_owner, _operator);
  }

  function supportsInterface(
    bytes4 interfaceId
  )
    public
    view
    virtual
    override(ERC1155Upgradeable, IERC165Upgradeable)
    returns (bool)
  {
    return ERC1155Upgradeable.supportsInterface(interfaceId);
  }
}

File 36 of 44 : LibIMPT.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.17;

import "../../interfaces/IAccessManager.sol";

/// @title LibIMPT
/// @author Github: Labrys-Group
/// @dev Library for implementing frequently re-used functions, errors, events and data structures / state in IMPT
library LibIMPT {
  //######################
  //#### PUBLIC STATE ####

  bytes32 public constant IMPT_ADMIN_ROLE = keccak256("IMPT_ADMIN_ROLE");
  bytes32 public constant IMPT_BACKEND_ROLE = keccak256("IMPT_BACKEND_ROLE");
  bytes32 public constant IMPT_APPROVED_DEX = keccak256("IMPT_APPROVED_DEX");
  bytes32 public constant IMPT_MINTER_ROLE = keccak256("IMPT_MINTER_ROLE");
  bytes32 public constant IMPT_SALES_MANAGER = keccak256("IMPT_SALES_MANAGER");
  bytes32 public constant DEFAULT_ADMIN_ROLE = bytes32(0);

  //################
  //#### ERRORS ####

  ///@dev Thrown when _checkZeroAddress is called with the zero addres.
  error CannotBeZeroAddress();
  ///@dev Thrown when an auth signature from the IMPT back-end is invalid
  error InvalidSignature();
  ///@dev Thrown when an auth signature from the IMPT back-end  has expired
  error SignatureExpired();

  /// @dev Thrown when a custom checkRole function is used and the caller does not have the required role
  error MissingRole(bytes32 _role, address _account);

  ///@dev Emitted when the IMPT treasury changes
  event IMPTTreasuryChanged(address _implementation);

  //############################
  //#### INTERNAL FUNCTIONS ####

  ///@dev Internal function that checks if an address is zero and reverts if it is.
  ///@param _address The address to check.
  function _checkZeroAddress(address _address) internal pure {
    if (_address == address(0)) {
      revert CannotBeZeroAddress();
    }
  }

  function _hasIMPTRole(
    bytes32 _role,
    address _address,
    IAccessManager _AccessManager
  ) internal view {
    if (!(_AccessManager.hasRole(_role, _address))) {
      revert MissingRole(_role, msg.sender);
    }
  }
}

File 37 of 44 : SigRecovery.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.17;

/// @title SigRecovery
/// @dev This contract provides some helpers for signature recovery
library SigRecovery {
  /// @dev This method prefixes the provided message parameter with the message signing prefix, it also hashes the result as this hash is used in signature recovery
  /// @param _message The message to prefix
  function prefixMessageHash(
    bytes32 _message
  ) internal pure returns (bytes32 prefixedMessageHash) {
    prefixedMessageHash = keccak256(
      abi.encodePacked("\x19Ethereum Signed Message:\n32", _message)
    );
  }

  /// @dev This method splits the signature, extracting the r, s and v values
  /// @param _sig The signature to split
  function splitSignature(
    bytes memory _sig
  ) internal pure returns (bytes32 r, bytes32 s, uint8 v) {
    require(_sig.length == 65, "Sig: Invalid signature length");

    assembly {
      // First 32 bytes holds the signature length, skips first 32 bytes as that is the prefix
      r := mload(add(_sig, 32))
      // Gets the following 32 bytes of the signature
      s := mload(add(_sig, 64))
      // Get the final byte (first byte of the next 32 bytes)
      v := byte(0, mload(add(_sig, 96)))
    }
  }

  /// @dev This method prefixes the provided message hash, splits the signature and uses ecrecover to return the signing address
  /// @param _message The message that was signed
  /// @param _signature The signature
  function recoverAddressFromMessage(
    bytes memory _message,
    bytes memory _signature
  ) internal pure returns (address recoveredAddress) {
    bytes32 hashOfMessage = prefixMessageHash(keccak256(_message));

    (bytes32 r, bytes32 s, uint8 v) = splitSignature(_signature);

    recoveredAddress = ecrecover(hashOfMessage, v, r, s);
  }
}

File 38 of 44 : IAccessManager.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.17;

import "@openzeppelin/contracts/access/IAccessControlEnumerable.sol";

/// @title Interface for the AccessManager Smart Contract
/// @author Github: Labrys-Group
/// @notice Utilised to house all authorised accounts within the IMPT contract eco-system
interface IAccessManager is IAccessControlEnumerable {
  struct ConstructorParams {
    address superUser;
  }

  /// @dev throws when the array lengths do not match when bulk granting roles
  error ArrayLengthMismatch();

/// @dev used to grant roles to specific addresses in bulk
/// @param _roles an array of roles encoded into bytes
/// @param _addresses the addresses to grant the roles to, in order of roles listed
  function bulkGrantRoles(
    bytes32[] calldata _roles,
    address[] calldata _addresses
  ) external;

/// @dev sets the admin role for approved DEX and Sales Managers
  function transferDEXRoleAdmin() external;
}

File 39 of 44 : ICarbonCreditNFT.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.17;

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

import "./IMarketplace.sol";
import "./IAccessManager.sol";
import "./IInventory.sol";
import "./ISoulboundToken.sol";

/// @title ICarbonCreditNFT
/// @author Github: Labrys-Group
/// @dev This interface represents a carbon credit non-fungible token (NFT). It extends the IERC1155 interface to allow for the creation and management of carbon credits.
interface ICarbonCreditNFT is IERC1155Upgradeable {
  /// @dev The `TransferAuthorisationParams` struct holds the parameters required to authorisation a token transfer, this struct will be signed by a backend wallet. Only KYCed users can hold CarbonCreditNFT's and this authorisation ensures that the Backend has checked that the 'to' address belongs to a KYCed user
  /// @param expiry representing the request UNIX expiry time
  /// @param to The receiver of the transfer
  struct TransferAuthorisationParams {
    uint40 expiry;
    address to;
  }

  /// @dev The `ConstructorParams` struct holds the parameters that are required to be passed to the contract's constructor.
  /// @param superUser The address of the superuser of the contract.
  /// @param baseURI The base URI for the NFT contract
  struct ConstructorParams {
    address superUser;
    address platformAdmin;
    string baseURI;
    IAccessManager AccessManager;
    string name;
    string symbol;
  }

  /// @dev The `RetirementParams` struct holds the parameters that are required to be passed to the retire function.
  /// @param tokenId The id of the token being retired.
  /// @param amount The amount of the token being retired.
  /// @param claimPercentage The percentage of the tokens price that is claimable by the user
  /// @param swapPercentage The percentage of the tokens price that is gathered from uniswap by swapping USDC for IMPT
  /// @param usdcswapPercentage The amount of USDC to swap for IMPT
  /// @param expiry The UNIX expiry time of the request
  /// @param signature The signature of the request
  /// @param swapPath The path to swap USDC for IMPT (USDC -> WETH -> IMPT)
  struct RetirementParams {
    uint256 tokenId;
    uint256 amount;
    uint256 claimPercentage;
    uint256 swapPercentage;
    uint256 usdcSwapAmount;
    uint40 expiry;
    bytes signature;
    bytes swapPath;
  }

  //################
  //#### ERRORS ####
  //################

  /// @dev The `MustBeMarketplaceContract` error is thrown if the contract being interacted with is not the marketplace contract
  error MustBeMarketplaceContract();

  /// @dev This error is thrown when calling the safeTransferFrom or safeBatchTransferFrom with the standard ERC1155 transfer parameters. This is disabled because we require a backend signature in order to transfer tokens, this requires disabling the base method and overloading it with a new one that includes the additional parameters
  error TransferMethodDisabled();

  //###################
  //#### FUNCTIONS ####
  //###################

  /// @dev Returns the token uri for the provided token id
  /// @param _id The token id for which the URI is being retrieved.
  /// @return The token URI for the provided token id.
  function uri(uint256 _id) external view returns (string memory);

  /// @dev Allows user's with the IMPT_MINTER_ROLE to mint tokens. This function creates new tokens and assigns them to the specified address.
  /// @param _to The address to which the new tokens should be assigned.
  /// @param _id The token id for the new tokens being minted.
  /// @param _amount The number of tokens being minted.
  /// @param _data Optional data pass through incase we develop the token hooks later on
  /// @dev checks the inventory contract for available supply and updates accordingly after minting
  /// @dev This function is only callable when the contract is not paused
  function mint(
    address _to,
    uint256 _id,
    uint256 _amount,
    bytes memory _data
  ) external;

  /// @dev function used to set the sales manager contract address (needed for burning IMPT on retirement)
  /// @param _salesManager the address of the sales manager contract
  /// @dev This function is only callable by IMPT_ADMIN_ROLE
  function setSalesManager(address payable _salesManager) external;

  /// @dev Burns the NFT token and increments retire/burn counts for soulbound and inventory contracts, respectively
  /// @param _retirementParams The retirement parameters - see struct above for documentation
  /// @dev This function is only callable when the contract is not paused
  function retire(RetirementParams calldata _retirementParams) external;

  /// @dev Allows user's with the IMPT_MINTER_ROLE to batch mint multiple token id's with varying amounts to a specified user. This function creates new tokens and assigns them to the specified address.
  /// @param _to The address to which the new tokens should be assigned.
  /// @param _ids An array of token id's for the new tokens being minted.
  /// @param _amounts An array of the number of tokens being minted for each corresponding token id in the ids array.
  /// @param _data Optional data pass through incase we develop the token hooks later on
  /// @dev checks the inventory contract for available supply and updates accordingly after minting
  /// @dev This function is only callable when the contract is not paused
  function mintBatch(
    address _to,
    uint256[] memory _ids,
    uint256[] memory _amounts,
    bytes memory _data
  ) external;

  /// @dev Allows user's to transfer their CarbonCreditNFT to a KYCed user. The TransferAuthorisationParams contains the destination to address and the backendSignature ensures that the backend has validated the address to be a KYCed user.
  /// @param _from The from address
  /// @param _id The tokenId to transfer
  /// @param _amount The amount of tokenId's to transfer
  /// @param _backendSignature The signed TransferAuthorisationParams by the backend
  /// @param _transferAuthParams The transfer parameters
  /// @dev This function is only callable when the contract is not paused
  function transferFromBackendAuth(
    address _from,
    uint256 _id,
    uint256 _amount,
    TransferAuthorisationParams calldata _transferAuthParams,
    bytes calldata _backendSignature
  ) external;

  /// @dev Allows user's to transfer multiple CarbonCreditNFT's to a KYCed user. The TransferAuthorisationParams contains the destination to address and the backendSignature ensures that the backend has validated the address to be a KYCed user.
  /// @param _from The from address
  /// @param _ids The id's to transfer
  /// @param _amounts Equivalent length array containing the amount of each tokenId to transfer
  /// @param _backendSignature The signed TransferAuthorisationParams by the backend
  /// @param _transferAuthParams The transfer parameters
  /// @dev This function is only callable when the contract is not paused
  function batchTransferFromBackendAuth(
    address _from,
    uint256[] memory _ids,
    uint256[] memory _amounts,
    TransferAuthorisationParams calldata _transferAuthParams,
    bytes calldata _backendSignature
  ) external;

  //################
  //#### EVENTS ####

  /// @dev The `MarketplaceContractChanged` event is emitted whenever the contract's associated marketplace contract is changed.
  /// @param _implementation The new implementation of the marketplace contract.
  event MarketplaceContractChanged(IMarketplace _implementation);

  /// @dev The `InventoryContractChanged` event is emitted whenever the contract's associated inventory contract is changed.
  /// @param _implementation The new implementation of the inventory contract.
  event InventoryContractChanged(IInventory _implementation);

  /// @dev The `SoulboundContractChanged` event is emitted whenever the contract's associated soulbound token contract is changed.
  /// @param _implementation The new implementation of the soulbound contract.
  event SoulboundContractChanged(ISoulboundToken _implementation);

  /// @dev The `BaseURIUpdated` event is emitted whenever the contract's baseUri is updated
  /// @param _baseUri The new baseUri to set
  event BaseUriUpdated(string _baseUri);

  //##########################
  //#### SETTER-FUNCTIONS ####

  /// @dev The `setBaseUri` function sets the baseURI for the contract, the provided baseUri is concatted with the address of the contract so that the uri for tokens is: `${baseUri}/${address(this)}/${tokenId}`
  /// @param _baseUri The new base uri for the contract
  function setBaseUri(string calldata _baseUri) external;

  /// @dev The `setMarketplaceContract` function sets the marketplace contract
  /// @param _marketplaceContract The new implementation of the marketplace contract.
  function setMarketplaceContract(IMarketplace _marketplaceContract) external;

  /// @dev The `setInventoryContract` function sets the inventory contract
  /// @param _inventoryContract The new implementation of the inventory contract.
  function setInventoryContract(IInventory _inventoryContract) external;

  /// @dev The `setSoulboundContract` function sets the soulbound token contract
  /// @param _soulboundContract The new implementation of the soulbound token contract.
  function setSoulboundContract(ISoulboundToken _soulboundContract) external;

  /// @dev This function allows the platform admin to pause the contract.
  function pause() external;

  /// @dev This function allows the platform admin to unpause the contract.
  function unpause() external;

  //################################
  //#### AUTO-GENERATED GETTERS ####
  /**
   * @dev Returns the name of the token.
   */
  function name() external view returns (string memory);

  /**
   * @dev Returns the symbol of the token, usually a shorter version of the
   * name.
   */
  function symbol() external view returns (string memory);

  /// @dev The `MarketplaceContract` function returns the address of the contract's associated marketplace contract.
  ///@return implementation The address of the contract's associated marketplace contract.
  function MarketplaceContract()
    external
    view
    returns (IMarketplace implementation);

  /// @dev This function returns the address of the IMPT Access Manager contract
  ///@return implementation The address of the contract's associated AccessManager contract.
  function AccessManager()
    external
    view
    returns (IAccessManager implementation);

  /// @dev The `InventoryContract` function returns the address of the contract's associated inventory contract.
  ///@return implementation The address of the contract's associated inventory contract.
  function InventoryContract()
    external
    view
    returns (IInventory implementation);

  /// @dev The `SoulboundContract` function returns the address of the contract's associated inventory contract.
  ///@return implementation The address of the contract's associated inventory contract.
  function SoulboundContract()
    external
    view
    returns (ISoulboundToken implementation);

  /// @dev function called by the SalesManager to bulk retire tokens as part of the bulkMintAndRetire function
  /// @param _tokenIds the token ids to retire
  /// @param _amounts the amounts of each token id to retire
  function bulkRetire(
    uint256[] calldata _tokenIds,
    uint256[] calldata _amounts
  ) external;
}

File 40 of 44 : IInventory.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.17;
import "../implementations/CarbonCreditNFT.sol";
import "./IAccessManager.sol";

interface IInventory {
  struct InventoryConstructorParams {
    address stableWallet;
    CarbonCreditNFT nftContract;
    IAccessManager AccessManager;
  }

  /// @dev stores the starge details for a particular token ID
  struct TokenDetails {
    uint256 totalSupply;
    uint256 tokensMinted;
    uint256 imptBurnCount;
  }

  //####################################
  //#### ERRORS #######################
  //####################################
  /// @dev reverts if the function is called by an unauthorized address
  error UnauthorizedCall();

  /// @dev reverts function if updating totals will result in negatives (to be used where functions might panic instead)
  error TotalMismatch();

  /// @dev reverts function if amount is less than 0
  error AmountMustBeMoreThanZero();

  /// @dev reverts a function if there is not enough total supply for a given token
  error NotEnoughSupply();

  //###################################
  //#### EVENTS #######################
  //###################################
  /// @dev emits when the burn count has been updated
  /// @param _tokenId the id of the token whose burn count has been updated
  /// @param _amount the number of tokens burned
  event BurnCountUpdated(uint256 _tokenId, uint256 _amount);

  /// @dev emits when the burn count has been sent to Thallo
  /// @param _tokenId the id of the token whose burn count has been sent
  /// @param _amount the number of tokens sent to be burned by Thallo
  event BurnSent(uint256 _tokenId, uint256 _amount);

  /// @dev emits when the burn count has been confirmed by Thallo
  /// @param _tokenId the id of the token whose burn count is confirmed
  /// @param _amount the amount of tokens confirmed burned by Thallo
  event BurnConfirmed(uint256 _tokenId, uint256 _amount);

  /// @dev emits when the total supply has been sent by Thallo
  /// @param _tokenId the id of the token whose supply has been updated
  /// @param _newSupply the updated total supply of the token
  event TotalSupplyUpdated(uint256 indexed _tokenId, uint256 _newSupply);

  /// @dev emits when the stable wallet has been updated
  /// @param _newStableWallet the address of the new stable walelt
  event UpdateWallet(address _newStableWallet);

  //####################################
  //#### FUNCTIONS #####################
  //####################################
  /// @dev updates the total supply of a given token ID, as given by Thallo
  /// @param _tokenId the Carbon Credit NFT's token ID (ERC-1155)
  /// @param _amount the amount that the total will be set to
  function updateTotalSupply(uint256 _tokenId, uint256 _amount) external;

  /// @dev updates the total supply of a given token ID, as given by Thallo
  /// @param _tokenIds an array of the Carbon Credit NFT's token IDs (ERC-1155)
  /// @param _amounts an array of the amounts that the total will be set to
  function updateBulkTotalSupply(
    uint256[] memory _tokenIds,
    uint256[] memory _amounts
  ) external;

  /// @dev returns the total supply of a given token ID
  /// @param _tokenIds an array of the Carbon Credit NFT's token IDs (ERC-1155)
  function getAllTokenDetails(
    uint256[] memory _tokenIds
  ) external view returns (TokenDetails[] memory);

  /// @dev updates the IMPT burn count when a carbon NFT is retired
  /// @param _tokenId the token ID for update burn counts for
  /// @param _amount the amount to increment the burn count by
  function incrementBurnCount(uint256 _tokenId, uint256 _amount) external;

  /// @dev this function calls the confirm burn counts and update total supply functions in a single transaction
  /// @param _tokenId the Carbon Credit NFT token ID
  /// @param _newTotalSupply the amount to which to total supply will be set
  /// @param _confirmedBurned the amount that Thallo has confirmed burned on their end
  function confirmAndUpdate(
    uint256 _tokenId,
    uint256 _newTotalSupply,
    uint256 _confirmedBurned
  ) external;

  function bulkConfirmAndUpdate(
    uint256[] memory _tokenIds,
    uint256[] memory _newTotalSupplies,
    uint256[] memory _confirmedBurns
  ) external;

  /// @dev Updates total when Thallo confirms the number of tokens burned to IMPT
  /// @param _tokenId the Carbon Credit NFT's token ID (ERC-1155)
  /// @param _amount the amount of tokens Thallo has burned
  function confirmBurnCounts(uint256 _tokenId, uint256 _amount) external;

  /// @dev Updates totals in bulk when Thallo confirms the number of tokens burned to IMPT
  /// @param _tokenIds the Carbon Credit NFT's token IDs (ERC-1155)
  /// @param _amounts the amounts of tokens Thallo has burned
  function bulkConfirmBurnCounts(
    uint256[] memory _tokenIds,
    uint256[] memory _amounts
  ) external;

  /// @dev The wallet that is able to sign contracts on behalf of IMPT
  /// @param _stableWallet the wallet address
  function setStableWallet(address _stableWallet) external;

  /// @dev The wallet that is able to sign contracts on behalf of IMPT
  /// @param _nftContract the address of the carbon credit NFT
  function setNftContract(CarbonCreditNFT _nftContract) external;

  /// @dev decrements the total supply, to be called whenever carbon credit tokens are minted
  /// @param _tokenId the id of the token id that needs to be decremented
  /// @param _amount the amount by which to decrement the total supply
  function updateTotalMinted(uint256 _tokenId, uint256 _amount) external;

  //####################################
  //#### GETTERS #######################
  //####################################
  /// @dev The stable wallet is an admin-controlled wallet
  function stableWallet() external returns (address);

  /// @dev The nftContract is the Carbon Credit NFT
  function nftContract() external returns (CarbonCreditNFT);

  /// @dev This function returns the address of the IMPT Access Manager contract
  function AccessManager()
    external
    view
    returns (IAccessManager implementation);
}

File 41 of 44 : IMarketplace.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.17;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

import "../interfaces/ICarbonCreditNFT.sol";
import "../interfaces/IAccessManager.sol";

/// @title Interface for the IMarketplace Smart Contract
/// @author Github: Labrys-Group
interface IMarketplace {
  //################
  //#### STRUCTS ###

  /// @dev This struct represents the parameters required to construct a marketplace contract.
  /// @param superUser The address of the superuser of the contract
  /// @param platformAdmin The address of the platform admin of the contract
  /// @param CarbonCreditNFT The address of the carbon credit NFT contract
  /// @param IMPTAddress The address of the IMPT ERC20 contract
  /// @param IMPTTreasuryAddress The address of the IMPT treasury contract
  struct ConstructorParams {
    ICarbonCreditNFT CarbonCreditNFT;
    IERC20 IMPTAddress;
    address IMPTTreasuryAddress;
    IAccessManager AccessManager;
  }

  /// @dev This struct represents a sale order for carbon credits
  /// @param saleOrderId The unique identifier for this sale order, this will be invalidated within the method to ensure no double-spends
  /// @param tokenId The token ID of the carbon credit being sold
  /// @param amount The amount of carbon credits being sold
  /// @param salePrice The price at which the carbon credits are being sold
  /// @param expiry The expiration timestamp for this sale order
  /// @param seller The address of the seller
  struct SaleOrder {
    bytes24 saleOrderId;
    uint256 tokenId;
    uint256 amount;
    uint256 salePrice;
    uint40 expiry;
    address seller;
  }

  /// @dev This struct contains the authorisation parameters for a sale request, this will be provided along with a SaleOrder. This struct will be signed by the backend, as it will check if the 'to' address is KYCed and the expiry will ensure the request cannot live too long
  /// @param expiry This authorisation expiry will be a short duration ~5 mins and allows users to delist their tokens or change the sell order without risking another user saving the sellerSignature to be executed later on
  /// @param to The address that will receive the purchased tokens
  struct AuthorisationParams {
    uint40 expiry;
    address to;
  }

  //####################################
  //#### ERRORS #######################
  //####################################

  /// @dev This error is thrown when a sale order has expired.
  error SaleOrderExpired();

  /// @dev This error is thrown when the seller does not have sufficient carbon credits to fulfill the sale.
  error InsufficientSellerCarbonCreditBalance();

  /// @dev This error is thrown when the buyer does not have sufficient balance of IMPT to fulfill the purchase.
  error InsufficientTokenBalance();

  /// @dev This error is thrown when a sale order with the same ID has already been used.
  error SaleOrderIdUsed();

  /// @dev This error is thrown when a user is trying to use AuthorisationParams where the to address doesn't match the msg.sender
  error InvalidBuyer();

  //####################################
  //#### EVENTS #######################
  //####################################

  /// @dev This event is emitted when a carbon credit sale is completed.
  /// @param _saleOrderId The unique identifier for the sale order.
  /// @param _tokenId The token ID of the carbon credit being sold.
  /// @param _amount The amount of carbon credits being sold.
  /// @param _salePrice The price at which the carbon credits were sold.
  /// @param _seller The address of the seller.
  /// @param _buyer The address of the buyer.
  event CarbonCreditSaleCompleted(
    bytes24 _saleOrderId,
    uint256 _tokenId,
    uint256 _amount,
    uint256 _salePrice,
    address indexed _seller,
    address indexed _buyer
  );

  /// @dev This event is emitted when the royalty percentage changes.
  /// @param _royaltyPercentage The new royalty percentage.
  event RoyaltyPercentageChanged(uint256 _royaltyPercentage);

  //####################################
  //#### SETTER-FUNCTIONS #############
  //####################################

  /// @dev This function allows the platform admin to set the address of the IMPT treasury contract.
  /// @param _implementation The address of the IMPT treasury contract.
  function setIMPTTreasury(address _implementation) external;

  /// @dev This function allows the platform admin to set the royalty percentage.
  /// @param _royaltyPercentage The new royalty percentage.
  function setRoyaltyPercentage(uint256 _royaltyPercentage) external;

  /// @dev This function allows the platform admin to pause the contract.
  function pause() external;

  /// @dev This function allows the platform admin to unpause the contract.
  function unpause() external;

  //####################################
  //#### AUTO-GENERATED GETTERS #######
  //####################################

  /// @dev This function returns the address of the IMPT ERC20 contract.
  /// @return _implementation The address of the IMPT ERC20 contract.
  function IMPTAddress() external returns (IERC20 _implementation);

  /// @dev This function returns the address of the carbon credit NFT contract.
  /// @return _implementation The address of the carbon credit NFT contract.
  function CarbonCreditNFT() external returns (ICarbonCreditNFT _implementation);

  /// @dev This function returns the address of the IMPT treasury contract.
  /// @return _implementation The address of the IMPT treasury contract.
  function IMPTTreasuryAddress() external returns (address _implementation);

  /// @dev This function returns whether the specified sale order ID has been used.
  /// @param _saleOrderId The sale order ID to check.
  /// @return used True if the sale order ID has been used, false otherwise.
  function usedSaleOrderIds(bytes24 _saleOrderId) external returns (bool used);

  /// @dev This function returns the address of the IMPT Access Manager contract
  function AccessManager() external returns (IAccessManager implementation);

  /// @dev This method executes the provided sale order, charging the seller their sale amount and transferring the msg.sender the tokens. It also takes a royalty percentage from the sale and transfers it to the IMPT treasury. This method also ensures that the _authorisationParams.to == msg.sender
  /// @param _authorisationParams The authorisation parameters from the backend
  /// @param _authorisationSignature The signed saleOrder + authorisationParams
  /// @param _saleOrder The sale order details
  /// @param _sellerOrderSignature The seller's signature
  function purchaseToken(
    AuthorisationParams calldata _authorisationParams,
    bytes calldata _authorisationSignature,
    SaleOrder calldata _saleOrder,
    bytes calldata _sellerOrderSignature
  ) external;
}

File 42 of 44 : ISalesManager.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.17;

import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
import "@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol";

import "./ICarbonCreditNFT.sol";
import "./ISoulboundToken.sol";
import "../vendors/IWETH.sol";

/// @title Interface for the SalesManager Smart Contract
/// @author Github: Labrys-Group
/// @notice Utilised to correctly route a user's swap transaction, enforcing constraints on permitted swapTargets and balance changes of known tokens.
/// @dev Checks balance change of IMPTToken == sellAmount
/// @dev Checks balance change of USDC is more than zero
/// @dev Utilises the internal Solidity Library `LibIMPT`
interface ISalesManager {
  //################
  //#### STRUCTS ###
  //################

  /// @dev Struct to hold authorisation parameters
  /// @param requestId bytes24 representing the request identifier from the IMPT back-end
  /// @param expiry uint40 representing the request UNIX expiry time
  /// @param sellAmount uint256 representing the amount of tokens to be sold
  /// @param tokenId the tokenId the user is purchasing
  /// @param amount amount of tokenId's to purchase
  /// @param burnPercentage the percentage of the amount to be burnt (held in this contract until burn takes place)
  /// @param minimumAmount the minimum amount of tokens to be received from the swap
  /// @param claimPercentage The percentage of the burn value to be paid to the user at the time of token retirement
  /// @param userAddress address of the user claiming the reward (address(0) if web3 mints), user address or default for web2 mints
  /// @param signature bytes representing signature of this message (signed by a role with IMPT_BACKEND_ROLE)
  /// @param swapPath bytes representing the swap path
  struct AuthorisationParams {
    bytes24 requestId;
    uint40 expiry;
    uint256 sellAmount;
    uint256 tokenId;
    uint256 amount;
    uint256 burnPercentage;
    uint256 minimumSwapAmount;
    uint256 claimPercentage;
    address userAddress;
    bytes signature;
    bytes swapPath;
  }

  /// @dev Struct to hold authorisation parameters
  /// @param requestId bytes24 representing the request identifier from the IMPT back-end
  /// @param sellAmount uint256 representing the amount of tokens to be sold
  /// @param tokenId the tokenId the user is purchasing
  /// @param amount amount of tokenId's to purchase
  /// @param burnPercentage the percentage of the amount to be burnt (held in this contract until burn takes place)
  /// @param swapPercentage the percentage of the amount to be gotten through a swap of USDC -> IMPT
  /// @param claimPercentage The percentage of the burn value to be paid to the user at the time of token retirement
  /// @param usdcSwapAmount the amount of USDC to swap for IMPT
  /// @param userAddress address of the user claiming the reward (address(0) if web3 mints), user address or default for web2 mints
  struct BulkPurchaseAndRetire {
    bytes24 requestId;
    uint256 sellAmount;
    uint256 tokenId;
    uint256 amount;
    uint256 burnPercentage;
    uint256 swapPercentage;
    uint256 claimPercentage;
    uint256 usdcSwapAmount;
    address userAddress;
  }

  /// @dev Struct to hold bulk purchase and retire parameters
  /// @param bulkPurchaseAndRetire array of BulkPurchaseAndRetire structs
  /// @param swapPath bytes representing the swap path
  struct BulkPurchaseAndRetireParams {
    BulkPurchaseAndRetire[] bulkPurchaseAndRetire;
    bytes swapPath;
  }

  /// @dev Struct to hold user reward claim parameters
  /// @param requestId bytes24 representing the request identifier from the IMPT back-end
  /// @param expiry uint40 representing the request UNIX expiry time
  /// @param user address of the user claiming the reward
  /// @param amount uint256 representing the amount of tokens to be claimed
  /// @param signature bytes representing signature of this message (signed by a role with IMPT_BACKEND_ROLE)
  struct UserRewardClaim {
    bytes24 requestId;
    uint40 expiry;
    address user;
    uint256 amount;
    bytes signature;
  }

  /// @dev Struct to hold swap parameters
  /// @param spender address of the spender
  /// @param swapTarget address of the swap target
  /// @param swapCallData data for the swap call
  struct SwapParams {
    address spender;
    address swapTarget;
    bytes swapCallData;
  }

  /// @dev Struct to hold constructor parameters
  /// @param IMPTAddress address of the IMPT token contract
  /// @param USDCAddress address of the USDC token contract
  /// @param WETHAddress address of the WETH token contract
  /// @param CarbonCreditNFTContract address of the CarbonCreditNFT contract
  /// @param IMPTTreasuryAddress address of the IMPT treasury contract
  /// @param AccessManager  address of the IMPT Access Manager
  /// @param SoulboundToken address of the soulbound token contract
  struct ConstructorParams {
    IERC20Upgradeable IMPTAddress;
    IERC20Upgradeable USDCAddress;
    IWETH WETHAddress;
    ICarbonCreditNFT CarbonCreditNFTContract;
    address IMPTTreasuryAddress;
    IAccessManager AccessManager;
    ISoulboundToken SoulboundToken;
  }

  /// @dev Struct to hold swap return data
  /// @param IMPTDelta uint256 representing the change in the IMPT balance
  /// @param USDCDelta uint256 representing the change in the USDC balance
  struct SwapReturnData {
    uint256 IMPTDelta;
    uint256 USDCDelta;
  }

  //################
  //#### EVENTS ####

  /// @dev Event emitted when purchase is completed
  /// @param _requestId bytes24 representing the request identifier
  /// @param _purchaseAmount uint256 representing the amount of tokens purchased
  event PurchaseCompleted(bytes24 _requestId, uint256 _purchaseAmount);

  /// @dev Event emitted when the platform token is changed
  /// @param _implementation address of the new platform token contract
  event PlatformTokenChanged(IERC20Upgradeable _implementation);

  /// @dev Event emitted when the USDC token is changed
  /// @param _implementation address of the new USDC token contract
  event USDCChanged(IERC20Upgradeable _implementation);

  /// @dev Event emitted when the WETH token is changed
  /// @param _implementation address of the new WETH token contract
  event WETHChanged(IWETH _implementation);

  /// @dev Event emitted when the IMPT treasury is changed
  /// @param _implementation address of the new IMPT treasury contract
  event IMPTTreasuryChanged(address _implementation);

  /// @dev Event emitted whenever the CarbonCreditNFT contract is changed
  /// @param _implementation The new implementation of the CarbonCreditNFTcontract
  event CarbonCreditNFTContractChanged(ICarbonCreditNFT _implementation);

  /// @dev Event emitted whenever the Soulbound Token contract is changed
  /// @param _implementation The new implementation of the Soulbound Token contract
  event SoulboundTokenContractChanged(ISoulboundToken _implementation);

  /// @dev Event emitted when a soulbound token has been minted
  /// @param _owner the owner of a brand new soulbound token!
  /// @param _tokenId the soulbound token ID
  event SoulboundTokenMinted(address _owner, uint256 _tokenId);

  /// @dev Event emitted when a user reward has been claimed
  /// @param _requestId bytes24 representing the request identifier
  /// @param _amount uint256 representing the amount of tokens claimed
  event UserRewardClaimed(
    bytes24 _requestId,
    address recipient,
    uint256 _amount
  );

  /// @dev Event emitted when a user has burned their tokens
  event UserRewardsClaimEligible(
    uint256 _tokenId,
    uint256 _amount,
    uint256 indexed _burnAmount,
    uint256 _claimPercentage,
    uint256 indexed _claimAmount,
    address _user
  );

  //################
  //#### ERRORS ####

  /// @dev Thrown when a swapTarget attemts to be called that doesn't hold IMPT_APPROVED_DEX role
  error UnauthorisedSwapTarget();
  /// @dev Thrown when the low-level call to the swapTarget fails
  error ZeroXSwapFailed();
  /// @dev Thrown if SwapReturnData.USDCDelta isn't > 0
  error WrongBuyTokenChange();
  /// @dev Thrown if IMPTDelta != AuthorisationParams.sellAmount
  error WrongSellTokenChange();

  //###################
  //#### FUNCTIONS ####
  //

  /// @dev Fallback function to receive payments
  receive() external payable;

  /// @notice Function to purchase tokens with IMPT
  /// @param _authorisationParams AuthorisationParams struct representing the authorisation parameters
  /// @param _swapParams SwapParams struct representing the swap parameters
  /// @dev Checks balance change of IMPT token == sellAmount
  /// @dev Checks balance change of USDC is more than zero
  /// @dev Uses OpenZeppelin AccessControl to restrict approved Decentralised Exchanges
  /// @dev Uses OpenZeppelin AccessControl to restrict approved IMPT Admins for setter functions
  /// @dev Utilises the internal Solidity Library `LibIMPT`
  function purchaseWithIMPT(
    AuthorisationParams calldata _authorisationParams,
    SwapParams calldata _swapParams
  ) external;

  /// @notice Function to purchase tokens with IMPT but does not swap from IMPT => USDC
  /// @param _authorisationParams AuthorisationParams struct representing the authorisation parameters
  function purchaseWithIMPTWithoutSwap(
    AuthorisationParams calldata _authorisationParams
  ) external;

  /// @notice Function to purchase a soulbound token
  /// @param _authorisationParams AuthorisationParams struct representing the authorisation parameters
  function purchaseSoulboundToken(
    AuthorisationParams calldata _authorisationParams,
    string memory _imageURI
  ) external;

  /// @notice Function to add a swap target
  /// @param _implementation address of the swap target contract
  /// @dev Can only be called by an approved IMPT admin
  function addSwapTarget(address _implementation) external;

  /// @notice Function to remove a swap target
  /// @param _implementation address of the swap target contract
  /// @dev Can only be called by an approved IMPT admin
  function removeSwapTarget(address _implementation) external;

  //##########################
  //#### SETTER-FUNCTIONS ####

  /// @notice Function to set the platform token contract
  /// @param _implementation address of the new platform token contract
  /// @dev Can only be called by an approved IMPT admin
  function setPlatformToken(IERC20Upgradeable _implementation) external;

  /// @notice Function to set the USDC token contract
  /// @param _implementation address of the new USDC token contract
  /// @dev Can only be called by an approved IMPT admin
  function setUSDC(IERC20Upgradeable _implementation) external;

  /// @notice Function to set the WETH token contract
  /// @param _implementation address of the new WETH token contract
  /// @dev Can only be called by an approved IMPT admin
  function setWETH(IWETH _implementation) external;

  /// @notice Function to set the IMPT treasury contract
  /// @param _implementation address of the new IMPT treasury contract
  /// @dev Can only be called by an approved IMPT admin
  function setIMPTTreasury(address _implementation) external;

  /// @dev Function to set the CarbonCreditNFT contract
  /// @param _carbonCreditNFT The new implementation of the CarbonCreditNFT contract.
  function setCarbonCreditNFT(ICarbonCreditNFT _carbonCreditNFT) external;

  /// @dev Function to set the Soulbound Token contract
  /// @param _soulboundToken The new implementation of the Soulbound Token contract.
  function setSoulboundToken(ISoulboundToken _soulboundToken) external;

  /// @dev This function allows the platform admin to pause the contract.
  function pause() external;

  /// @dev This function allows the platform admin to unpause the contract.
  function unpause() external;

  //################################
  //#### AUTO-GENERATED GETTERS ####

  /// @notice Function to get the address of the carbon credit NFT contract
  /// @return implementation address of the carbon credit NFT contract
  function CarbonCreditNFTContract()
    external
    returns (ICarbonCreditNFT implementation);

  /// @notice Function to get the address of the soulbound token contract
  /// @return implementation address of the soulbound token contract
  function SoulboundToken() external returns (ISoulboundToken implementation);

  /// @notice Function to get the address of the current platform token contract
  /// @return implementation address of the current platform token contract
  function IMPTAddress() external returns (IERC20Upgradeable implementation);

  /// @notice Function to get the address of the current USDC token contract
  /// @return implementation address of the current USDC token contract
  function USDCAddress() external returns (IERC20Upgradeable implementation);

  /// @notice Function to get the address of the current WETH token contract
  /// @return implementation address of the current WETH token contract
  function WETHAddress() external returns (IWETH implementation);

  /// @notice Function to get the address of the current IMPT treasury contract
  /// @return implementation address of the current IMPT treasury contract
  function IMPTTreasuryAddress() external returns (address implementation);

  /// @notice Function to check if a request has been used
  /// @param _requestId bytes24 representing the request identifier
  /// @return used bool indicating whether the request has been used or not
  function usedRequests(bytes24 _requestId) external returns (bool used);

  /// @notice Function to get the burn amount for a given token ID
  /// @dev The burn amount for a given token id is the sum of all the burn amounts for that token id
  ///      e.g, if the burn amount for token id 1 is 100, and the tokens circulating supply is 7, the burn amount should be 700
  /// @dev for a given token id - the burn amount must have 18 decimals
  /// @return burnAmount the uint256 which is the sum of the burn amount for a given token ID
  function burnAmounts(uint256 _tokenId) external returns (uint256 burnAmount);

  /// @notice Function to check if a claim has been used
  /// @param _requestId bytes24 representing the request identifier
  /// @return used bool indicating whether the claim has been used or not
  function usedClaims(bytes24 _requestId) external returns (bool used);

  /// @dev This function returns the address of the IMPT Access Manager contract
  function AccessManager() external returns (IAccessManager implementation);

  /// @dev This function returns the address of the Uniswap V3 Swap Router
  function SwapRouter() external returns (ISwapRouter swapRouter);

  /// @dev This function allows for the bulk purchase and retirement of tokens
  function bulkPurchaseAndRetire(
    BulkPurchaseAndRetireParams calldata _bulkPurchaseAndRetireParams
  ) external;

  /// lets the carbon credit nft contract burn the respective amount of tokens
  /// @param _retirementParams the struct containing the retirement parameters
  /// @param _supply the supply of the token
  /// @param _user the user who is retiring the tokens
  function retireAmount(
    ICarbonCreditNFT.RetirementParams calldata _retirementParams,
    uint256 _supply,
    address _user
  ) external;

  /// @notice Overrides the burn amount for a specific token
  /// @dev Sets the burn amount for a given token ID to a new value
  /// @param _tokenId The ID of the token for which to set the burn amount
  /// @param _burnAmount The new burn amount to set for the token
  /// @notice only callable by accounts with IMPT_ADMIN_ROLE
  function overrideBurnAmount(uint256 _tokenId, uint256 _burnAmount) external;

  /// @notice Updates the burn amount for a specific token
  /// @dev Increments the burn amount for a given token ID by a specified amount
  /// @param _tokenId The ID of the token for which to update the burn amount
  /// @param _burnAmount The amount to add to the current burn amount of the token
  /// @notice only callable by accounts with IMPT_ADMIN_ROLE
  function updateBurnAmount(uint256 _tokenId, uint256 _burnAmount) external;

  /// @notice Updates the burn amounts for multiple tokens in bulk
  /// @dev Increments the burn amounts for each given token ID by corresponding amounts in an array
  /// @param _tokenIds An array of token IDs for which to update the burn amounts
  /// @param _burnAmounts An array of amounts to add to the current burn amounts of the tokens
  /// @notice only callable by accounts with IMPT_ADMIN_ROLE
  function bulkUpdateBurnAmount(
    uint256[] calldata _tokenIds,
    uint256[] calldata _burnAmounts
  ) external;

  /// @notice the function to claim a user's rewards
  /// @param _rewardsClaim the struct containing the claim parameters
  function userRewardsClaim(UserRewardClaim calldata _rewardsClaim) external;

  /// @notice the function to set the uniswap router address on this contract
  function setUniswapRouter(address _router) external;

  /// @notice the function used to approve the uniswap router to move USDC tokens from this contract
  function approveUniswapRouter(address _router) external;
}

File 43 of 44 : ISoulboundToken.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.17;

import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import "../interfaces/ICarbonCreditNFT.sol";
import "../interfaces/IAccessManager.sol";

/// @dev Interface for a soulbound token which is non-transferrable and closely follows the 721 standard.
/// @dev It also manages the token types and formatting of metadata responses
interface ISoulboundToken is IERC165 {
  //################
  //#### STRUCTS ####
  /// @dev The `ConstructorParams` struct holds the parameters that are required to be passed to the contract's constructor.
  /// @param name_ The token name
  /// @param symbol_ The token symbol
  /// @param description_ The description of the token
  /// @param _carbonCreditContract The address of the carbon credit contract (must match interface specs)
  /// @param adminAddress The address that will be assigned to the role IMPT_ADMIN
  struct ConstructorParams {
    string name_;
    string symbol_;
    string description_;
    ICarbonCreditNFT _carbonCreditContract;
    IAccessManager AccessManager;
  }

  /// @dev The required fields for each tokenType. Each tokenType exists in the CarbonCreditNFT contract as a subcollection
  /// @param displayName Unique display name for the token type
  /// @param tokenId The id of the TokenType in the CarbonCreditNFT contract
  struct TokenType {
    string displayName;
    uint256 tokenId;
  }

  //################
  //#### EVENTS ####
  /// @dev This emits ONLY when token `_tokenId` is minted from the zero address and is used to conform closely to ERC721 standards
  event Transfer(
    address indexed _from,
    address indexed _to,
    uint256 indexed _tokenId
  );

  /// @dev Emits when the Carbon Credit contract has been updated
  event CarbonNftContractUpdated(ICarbonCreditNFT _newAddress);

  /// @dev Emits when the user's retire count for a given token ID is updated
  event RetireCountUpdated(address _owner, uint256 _tokenId, uint256 _amount);

  /// @dev Emits when a new token type is added
  event TokenTypeAdded(ISoulboundToken.TokenType _tokenType);

  /// @dev Emits when a new token type is removed
  event TokenTypeRemoved(uint256 _tokenId);

  //################
  //#### ERRORS ####
  /// @dev UnauthorizedCall throws an error if a call is made from an address without the correct role
  error UnauthorizedCall();

  /// @dev HasToken error is thrown if the target wallet for minting already has a token
  error HasToken();

  /// @dev TokenIdNotFound throws when passing a token ID into a function that does not exist
  error TokenIdNotFound();

  /// @dev NoTokenTypes throws if there have not been any token types added before trying to remove token types
  error NoTokenTypes();

  //##########################
  //#### CUSTOM FUNCTIONS ####
  /// @notice mints a new soulbound token
  /// @param _to the address to send the token to
  /// @param _imageURI the image URI for the token, to be included in the metadata
  function mint(address _to, string calldata _imageURI) external;

  /// @notice Increments the user's burned token count to be displayed in soulbound token metadata
  /// @param _user Address of the user whos burned count needs to be updated
  /// @param _tokenId The soulbound token ID owned by the user above
  /// @param _amount The amount by which to increase the user burned count
  function incrementRetireCount(
    address _user,
    uint256 _tokenId,
    uint256 _amount
  ) external;

  /// @notice returns all the current token types
  function getAllTokenTypes()
    external
    view
    returns (ISoulboundToken.TokenType[] memory);

  /// @notice adds a new token type
  /// @param _tokenType the data to add to the end of the token types array
  function addTokenType(TokenType calldata _tokenType) external;

  /// @notice removes token type from the array. If the token is not at the end of the array, the element at the end of the array is moved to the deleted item's position
  /// @param _tokenId the token ID of the token type, as from the CarbonCreditNFT
  function removeTokenType(uint256 _tokenId) external;

  /// @notice updates the carbon credit contract implementation
  /// @param _carbonCreditContract the new implementation of the carbon credit NFT
  function setCarbonCreditContract(
    ICarbonCreditNFT _carbonCreditContract
  ) external;

  /// @dev returns the current count of the token IDs (in other words, the next token ID to be minted)
  function getCurrentTokenId() external view returns (uint256);

  //###########################
  //#### ERC-721 FUNCTIONS ####
  /// @notice Returns the total amount of tokens for the provided user, can only ever be 0 or 1
  /// @param _owner An address for whom to query the balance
  /// @return The number of tokens owned by `_owner`, possibly zero
  function balanceOf(address _owner) external view returns (uint256);

  /// @notice Find the owner of a token
  /// @dev tokens assigned to zero address are considered invalid, and queries
  ///  about them do throw.
  /// @param _tokenId The identifier for a token
  /// @return The address of the owner of the token
  function ownerOf(uint256 _tokenId) external view returns (address);

  /// @notice The name of the Account Bound Token contract
  function name() external view returns (string memory);

  /// @notice The symbol of the Account Bound Token contract
  function symbol() external view returns (string memory);

  /// @notice The symbol of the Account Bound Token contract
  function description() external view returns (string memory);

  /// @notice TokenURI contains metadata for the individual token as base64 encoded JSON object
  /// @param _tokenId The token to retrieve a metadata URI for
  function tokenURI(uint256 _tokenId) external view returns (string memory);

  //################################
  //#### AUTO-GENERATED GETTERS ####
  /// @dev This function returns the address of the IMPT Access Manager contract
  ///@return implementation The address of the contract's associated AccessManager contract.
  function AccessManager()
    external
    view
    returns (IAccessManager implementation);

  /// @dev returns the current implementatino of the Carbon Credit NFT contract
  function carbonCreditContract() external view returns (ICarbonCreditNFT);

  /// @dev returns the number of tokens of a particular token ID that a user has burned
  /// @param owner the user's address
  /// @param tokenId the token ID for which to return the burn counts
  function usersBurnedCounts(
    address owner,
    uint256 tokenId
  ) external view returns (uint256);
}

File 44 of 44 : IWETH.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity 0.8.17;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

interface IWETH is IERC20 {
  function deposit() external payable;

  function withdraw(uint256 amount) external;
}

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

Contract Security Audit

Contract ABI

[{"inputs":[],"name":"CannotBeZeroAddress","type":"error"},{"inputs":[],"name":"InvalidSignature","type":"error"},{"inputs":[{"internalType":"bytes32","name":"_role","type":"bytes32"},{"internalType":"address","name":"_account","type":"address"}],"name":"MissingRole","type":"error"},{"inputs":[],"name":"SignatureExpired","type":"error"},{"inputs":[],"name":"UnauthorisedSwapTarget","type":"error"},{"inputs":[],"name":"WrongBuyTokenChange","type":"error"},{"inputs":[],"name":"WrongSellTokenChange","type":"error"},{"inputs":[],"name":"ZeroXSwapFailed","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"previousAdmin","type":"address"},{"indexed":false,"internalType":"address","name":"newAdmin","type":"address"}],"name":"AdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"beacon","type":"address"}],"name":"BeaconUpgraded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract ICarbonCreditNFT","name":"_implementation","type":"address"}],"name":"CarbonCreditNFTContractChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_implementation","type":"address"}],"name":"IMPTTreasuryChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IERC20Upgradeable","name":"_implementation","type":"address"}],"name":"PlatformTokenChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes24","name":"_requestId","type":"bytes24"},{"indexed":false,"internalType":"uint256","name":"_purchaseAmount","type":"uint256"}],"name":"PurchaseCompleted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract ISoulboundToken","name":"_implementation","type":"address"}],"name":"SoulboundTokenContractChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"SoulboundTokenMinted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IERC20Upgradeable","name":"_implementation","type":"address"}],"name":"USDCChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"implementation","type":"address"}],"name":"Upgraded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes24","name":"_requestId","type":"bytes24"},{"indexed":false,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"UserRewardClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"_burnAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_claimPercentage","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"_claimAmount","type":"uint256"},{"indexed":false,"internalType":"address","name":"_user","type":"address"}],"name":"UserRewardsClaimEligible","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IWETH","name":"_implementation","type":"address"}],"name":"WETHChanged","type":"event"},{"inputs":[],"name":"AccessManager","outputs":[{"internalType":"contract IAccessManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"CarbonCreditNFTContract","outputs":[{"internalType":"contract ICarbonCreditNFT","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"IMPTAddress","outputs":[{"internalType":"contract IERC20Upgradeable","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"IMPTTreasuryAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"SoulboundToken","outputs":[{"internalType":"contract ISoulboundToken","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"SwapRouter","outputs":[{"internalType":"contract ISwapRouter","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"USDCAddress","outputs":[{"internalType":"contract IERC20Upgradeable","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"WETHAddress","outputs":[{"internalType":"contract IWETH","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_implementation","type":"address"}],"name":"addSwapTarget","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_router","type":"address"}],"name":"approveUniswapRouter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"components":[{"internalType":"bytes24","name":"requestId","type":"bytes24"},{"internalType":"uint256","name":"sellAmount","type":"uint256"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"burnPercentage","type":"uint256"},{"internalType":"uint256","name":"swapPercentage","type":"uint256"},{"internalType":"uint256","name":"claimPercentage","type":"uint256"},{"internalType":"uint256","name":"usdcSwapAmount","type":"uint256"},{"internalType":"address","name":"userAddress","type":"address"}],"internalType":"struct ISalesManager.BulkPurchaseAndRetire[]","name":"bulkPurchaseAndRetire","type":"tuple[]"},{"internalType":"bytes","name":"swapPath","type":"bytes"}],"internalType":"struct ISalesManager.BulkPurchaseAndRetireParams","name":"_bulkPurchaseAndRetireParams","type":"tuple"}],"name":"bulkPurchaseAndRetire","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"_tokenIds","type":"uint256[]"},{"internalType":"uint256[]","name":"_burnAmounts","type":"uint256[]"}],"name":"bulkUpdateBurnAmount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"burnAmounts","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"contract IERC20Upgradeable","name":"IMPTAddress","type":"address"},{"internalType":"contract IERC20Upgradeable","name":"USDCAddress","type":"address"},{"internalType":"contract IWETH","name":"WETHAddress","type":"address"},{"internalType":"contract ICarbonCreditNFT","name":"CarbonCreditNFTContract","type":"address"},{"internalType":"address","name":"IMPTTreasuryAddress","type":"address"},{"internalType":"contract IAccessManager","name":"AccessManager","type":"address"},{"internalType":"contract ISoulboundToken","name":"SoulboundToken","type":"address"}],"internalType":"struct ISalesManager.ConstructorParams","name":"_params","type":"tuple"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256[]","name":"","type":"uint256[]"},{"internalType":"uint256[]","name":"","type":"uint256[]"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC1155BatchReceived","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC1155Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"uint256","name":"_burnAmount","type":"uint256"}],"name":"overrideBurnAmount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"proxiableUUID","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"bytes24","name":"requestId","type":"bytes24"},{"internalType":"uint40","name":"expiry","type":"uint40"},{"internalType":"uint256","name":"sellAmount","type":"uint256"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"burnPercentage","type":"uint256"},{"internalType":"uint256","name":"minimumSwapAmount","type":"uint256"},{"internalType":"uint256","name":"claimPercentage","type":"uint256"},{"internalType":"address","name":"userAddress","type":"address"},{"internalType":"bytes","name":"signature","type":"bytes"},{"internalType":"bytes","name":"swapPath","type":"bytes"}],"internalType":"struct ISalesManager.AuthorisationParams","name":"_authorisationParams","type":"tuple"},{"internalType":"string","name":"_imageURI","type":"string"}],"name":"purchaseSoulboundToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"bytes24","name":"requestId","type":"bytes24"},{"internalType":"uint40","name":"expiry","type":"uint40"},{"internalType":"uint256","name":"sellAmount","type":"uint256"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"burnPercentage","type":"uint256"},{"internalType":"uint256","name":"minimumSwapAmount","type":"uint256"},{"internalType":"uint256","name":"claimPercentage","type":"uint256"},{"internalType":"address","name":"userAddress","type":"address"},{"internalType":"bytes","name":"signature","type":"bytes"},{"internalType":"bytes","name":"swapPath","type":"bytes"}],"internalType":"struct ISalesManager.AuthorisationParams","name":"_authorisationParams","type":"tuple"},{"components":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"address","name":"swapTarget","type":"address"},{"internalType":"bytes","name":"swapCallData","type":"bytes"}],"internalType":"struct ISalesManager.SwapParams","name":"_swapParams","type":"tuple"}],"name":"purchaseWithIMPT","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"bytes24","name":"requestId","type":"bytes24"},{"internalType":"uint40","name":"expiry","type":"uint40"},{"internalType":"uint256","name":"sellAmount","type":"uint256"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"burnPercentage","type":"uint256"},{"internalType":"uint256","name":"minimumSwapAmount","type":"uint256"},{"internalType":"uint256","name":"claimPercentage","type":"uint256"},{"internalType":"address","name":"userAddress","type":"address"},{"internalType":"bytes","name":"signature","type":"bytes"},{"internalType":"bytes","name":"swapPath","type":"bytes"}],"internalType":"struct ISalesManager.AuthorisationParams","name":"_authorisationParams","type":"tuple"}],"name":"purchaseWithIMPTWithoutSwap","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_implementation","type":"address"}],"name":"removeSwapTarget","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"claimPercentage","type":"uint256"},{"internalType":"uint256","name":"swapPercentage","type":"uint256"},{"internalType":"uint256","name":"usdcSwapAmount","type":"uint256"},{"internalType":"uint40","name":"expiry","type":"uint40"},{"internalType":"bytes","name":"signature","type":"bytes"},{"internalType":"bytes","name":"swapPath","type":"bytes"}],"internalType":"struct ICarbonCreditNFT.RetirementParams","name":"_retirementParams","type":"tuple"},{"internalType":"uint256","name":"_supply","type":"uint256"},{"internalType":"address","name":"_user","type":"address"}],"name":"retireAmount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract ICarbonCreditNFT","name":"_carbonCreditNFT","type":"address"}],"name":"setCarbonCreditNFT","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_implementation","type":"address"}],"name":"setIMPTTreasury","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20Upgradeable","name":"_implementation","type":"address"}],"name":"setPlatformToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract ISoulboundToken","name":"_soulboundToken","type":"address"}],"name":"setSoulboundToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20Upgradeable","name":"_implementation","type":"address"}],"name":"setUSDC","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_uniswapRouter","type":"address"}],"name":"setUniswapRouter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IWETH","name":"_implementation","type":"address"}],"name":"setWETH","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"uint256","name":"_burnAmount","type":"uint256"}],"name":"updateBurnAmount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"}],"name":"upgradeTo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"upgradeToAndCall","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bytes24","name":"","type":"bytes24"}],"name":"usedClaims","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes24","name":"","type":"bytes24"}],"name":"usedRequests","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"bytes24","name":"requestId","type":"bytes24"},{"internalType":"uint40","name":"expiry","type":"uint40"},{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"signature","type":"bytes"}],"internalType":"struct ISalesManager.UserRewardClaim","name":"_rewardsClaim","type":"tuple"}],"name":"userRewardsClaim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_tokenAddress","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"withdrawERC20","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]

60a06040523060805234801561001457600080fd5b5060805161461461004c600039600081816115ed0152818161162d015281816118d50152818161191501526119a401526146146000f3fe60806040526004361061024a5760003560e01c80635b769f3c116101395780638c388a9d116100b6578063e83a5a551161007a578063e83a5a55146106f2578063e93032091461071f578063ef6318831461073f578063f23a6e611461075f578063f69296de1461078b578063ff0ad417146107ab57600080fd5b80638c388a9d1461062d578063b3e089a21461064d578063bc197c811461066d578063bea9849e146106b2578063c5e7be6d146106d257600080fd5b80636e105749116100fd5780636e105749146105985780636e7641a2146105b8578063742267df146105d85780637ded4b79146105f85780638456cb591461061857600080fd5b80635b769f3c146105005780635c975abb146105205780635ea7a11d146105385780635f48e4271461055857806367d5f3371461057857600080fd5b80632e1a7d4d116101c757806344004cc11161018b57806344004cc11461046a5780634dc32eff1461048a5780634f1ef286146104aa57806352d1902d146104bd5780635699517c146104e057600080fd5b80632e1a7d4d146103d557806330d75ba3146103f55780633659cfe6146104155780633f4ba83a14610435578063414fb4251461044a57600080fd5b80630f11f4e71161020e5780630f11f4e71461031557806319f2e4fc146103355780632432a9511461037557806325c855e4146103955780632b838d1b146103b557600080fd5b80630255a03b14610256578063060f958614610278578063077e2063146102b55780630af2a89b146102d55780630af88b24146102f557600080fd5b3661025157005b600080fd5b34801561026257600080fd5b506102766102713660046137aa565b6107db565b005b34801561028457600080fd5b5060c954610298906001600160a01b031681565b6040516001600160a01b0390911681526020015b60405180910390f35b3480156102c157600080fd5b506102766102d03660046137de565b610862565b3480156102e157600080fd5b5060ce54610298906001600160a01b031681565b34801561030157600080fd5b5060cb54610298906001600160a01b031681565b34801561032157600080fd5b5060cc54610298906001600160a01b031681565b34801561034157600080fd5b50610365610350366004613857565b60d36020526000908152604090205460ff1681565b60405190151581526020016102ac565b34801561038157600080fd5b506102766103903660046137aa565b610b50565b3480156103a157600080fd5b506102766103b0366004613872565b610bce565b3480156103c157600080fd5b506102766103d03660046138ac565b610cb7565b3480156103e157600080fd5b506102766103f03660046138e6565b6113ef565b34801561040157600080fd5b50610276610410366004613918565b611424565b34801561042157600080fd5b506102766104303660046137aa565b6115e3565b34801561044157600080fd5b506102766116c2565b34801561045657600080fd5b5061027661046536600461394c565b6116f5565b34801561047657600080fd5b506102766104853660046139b6565b611892565b34801561049657600080fd5b5060d154610298906001600160a01b031681565b6102766104b8366004613add565b6118cb565b3480156104c957600080fd5b506104d2611997565b6040519081526020016102ac565b3480156104ec57600080fd5b506102766104fb3660046137aa565b611a4a565b34801561050c57600080fd5b5061027661051b3660046137aa565b611ac8565b34801561052c57600080fd5b5060335460ff16610365565b34801561054457600080fd5b5060cf54610298906001600160a01b031681565b34801561056457600080fd5b506102766105733660046137aa565b611b46565b34801561058457600080fd5b50610276610593366004613b2c565b611bc4565b3480156105a457600080fd5b5060cd54610298906001600160a01b031681565b3480156105c457600080fd5b506102766105d33660046137aa565b611dcf565b3480156105e457600080fd5b506102766105f33660046137aa565b611f00565b34801561060457600080fd5b50610276610613366004613be3565b611f64565b34801561062457600080fd5b50610276611f9f565b34801561063957600080fd5b506102766106483660046137aa565b611fce565b34801561065957600080fd5b506102766106683660046137aa565b6120b7565b34801561067957600080fd5b50610699610688366004613c79565b63bc197c8160e01b95945050505050565b6040516001600160e01b031990911681526020016102ac565b3480156106be57600080fd5b506102766106cd3660046137aa565b612135565b3480156106de57600080fd5b506102766106ed366004613e1f565b612189565b3480156106fe57600080fd5b506104d261070d3660046138e6565b60d26020526000908152604090205481565b34801561072b57600080fd5b5060ca54610298906001600160a01b031681565b34801561074b57600080fd5b5061027661075a366004613ed7565b612345565b34801561076b57600080fd5b5061069961077a366004613f42565b63f23a6e6160e01b95945050505050565b34801561079757600080fd5b506102766107a6366004613be3565b6123d7565b3480156107b757600080fd5b506103656107c6366004613857565b60d06020526000908152604090205460ff1681565b60ce546000805160206145bf833981519152906001600160a01b0316610802823383612427565b61080b836124be565b60c980546001600160a01b0319166001600160a01b0385169081179091556040519081527f25a6b3bbb8afcb2bda3493ac1c231ce7bfc7de5d124a241d745dd3e47eb0dc44906020015b60405180910390a1505050565b60cc546001600160a01b031633146108e05760405162461bcd60e51b815260206004820152603660248201527f53616c65734d616e616765723a206f6e6c79204e465420636f6e74726163742060448201527531b0b71031b0b636103a3434b990333ab731ba34b7b760511b60648201526084015b60405180910390fd5b8235600090815260d260205260408120546108fc908490613fc0565b9050600061090e602086013583613fe2565b905060006064610922606088013584613fe2565b61092c9190613fc0565b905060006064610940604089013585613fe2565b61094a9190613fc0565b905060006109588284613ff9565b8835600090815260d2602052604081208054929350869290919061097d90849061400c565b90915550506040805160a081019091526000908061099e60e08c018c61401f565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201829052509385525050306020840152504260408084019190915260808d810135606085015290920181905260d154915163c04b8d5960e01b8152929350916001600160a01b039091169063c04b8d5990610a289085906004016140b5565b6020604051808303816000875af1158015610a47573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a6b919061410d565b905082811015610a8d5760405162461bcd60e51b81526004016108d790614126565b60c954604051630852cd8d60e31b8152600481018890526001600160a01b03909116906342966c6890602401600060405180830381600087803b158015610ad357600080fd5b505af1158015610ae7573d6000803e3d6000fd5b5050604080518d3581526020808f0135908201528d820135818301526001600160a01b038c16606082015290518793508992507f2ed5ae033d5e06c4036702046608787d0457d99dac8bf7e6f6dfcdb6402ace7d9181900360800190a350505050505050505050565b60ce546000805160206145bf833981519152906001600160a01b0316610b77823383612427565b610b80836124be565b60cd80546001600160a01b0319166001600160a01b0385169081179091556040519081527f3409e1dd669c1b9bba4e12677a0324b44dfb4943c62570d7b18215b74bd880fd90602001610855565b610bdf610bda82614167565b6124e5565b60c95460405163a9059cbb60e01b81526001600160a01b039091169063a9059cbb90610c15903390606086013590600401614209565b6020604051808303816000875af1158015610c34573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c589190614222565b507fcf0889de76897114c9424de6273503db7d78aea38e623201dca2f510feba8dd8610c876020830183613857565b6040805167ffffffffffffffff19929092168252336020830152606084810135838301529051918290030190a150565b610cbf612692565b60ce547f81d2ab4e362bdcb20cd7c861e0d022d10f4d86836828fdc77fc915bcf303a0c7906001600160a01b0316610cf8823383612427565b6000610d048480614244565b90506001600160401b03811115610d1d57610d1d6139f7565b604051908082528060200260200182016040528015610d46578160200160208202803683370190505b5090506000610d558580614244565b90506001600160401b03811115610d6e57610d6e6139f7565b604051908082528060200260200182016040528015610d97578160200160208202803683370190505b50905060005b610da78680614244565b905081101561125b5760006064610dbe8880614244565b84818110610dce57610dce61428d565b9050610120020160800135888060000190610de99190614244565b85818110610df957610df961428d565b9050610120020160200135610e0e9190613fe2565b610e189190613fc0565b90508060d26000610e298a80614244565b86818110610e3957610e3961428d565b905061012002016040013581526020019081526020016000206000828254610e619190613ff9565b90915550600090506064610e758980614244565b85818110610e8557610e8561428d565b9050610120020160a0013583610e9b9190613fe2565b610ea59190613fc0565b905060006040518060a001604052808a8060200190610ec4919061401f565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250505090825250306020820152426040820152606001610f148b80614244565b87818110610f2457610f2461428d565b9050610120020160e00135815260200160008152509050600060d160009054906101000a90046001600160a01b03166001600160a01b031663c04b8d59836040518263ffffffff1660e01b8152600401610f7e91906140b5565b6020604051808303816000875af1158015610f9d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fc1919061410d565b90506064610fcf8b80614244565b87818110610fdf57610fdf61428d565b9050610120020160c0013585610ff59190613fe2565b610fff9190613fc0565b6110099084613ff9565b8110156110285760405162461bcd60e51b81526004016108d790614126565b60c954604051630852cd8d60e31b8152600481018390526001600160a01b03909116906342966c6890602401600060405180830381600087803b15801561106e57600080fd5b505af1158015611082573d6000803e3d6000fd5b5061109392508c9150819050614244565b868181106110a3576110a361428d565b90506101200201604001358786815181106110c0576110c061428d565b60209081029190910101526110d58a80614244565b868181106110e5576110e561428d565b90506101200201606001358686815181106111025761110261428d565b602090810291909101015260646111198b80614244565b878181106111295761112961428d565b9050610120020160c001358561113f9190613fe2565b6111499190613fc0565b847f2ed5ae033d5e06c4036702046608787d0457d99dac8bf7e6f6dfcdb6402ace7d6111758d80614244565b898181106111855761118561428d565b90506101200201604001358d80600001906111a09190614244565b8a8181106111b0576111b061428d565b90506101200201606001358e80600001906111cb9190614244565b8b8181106111db576111db61428d565b9050610120020160c001358f80600001906111f69190614244565b8c8181106112065761120661428d565b9050610120020161010001602081019061122091906137aa565b604080519485526020850193909352918301526001600160a01b0316606082015260800160405180910390a384600101945050505050610d9d565b5060cc54604051630fbfeffd60e11b81526001600160a01b0390911690631f7fdffa90611290903090869086906004016142de565b600060405180830381600087803b1580156112aa57600080fd5b505af11580156112be573d6000803e3d6000fd5b5050505060005b6112cf8680614244565b9050811015611383577f20cbd058e5b03c253185d3b0b90f21ef8b22a6f136ae092e54eafe62ab1f17cf6113038780614244565b838181106113135761131361428d565b61132a926020610120909202019081019150613857565b6113348880614244565b848181106113445761134461428d565b905061012002016020013560405161137392919067ffffffffffffffff19929092168252602082015260400190565b60405180910390a16001016112c5565b5060cc5460405163f611c48160e01b81526001600160a01b039091169063f611c481906113b69085908590600401614330565b600060405180830381600087803b1580156113d057600080fd5b505af11580156113e4573d6000803e3d6000fd5b505050505050505050565b60ce546000805160206145bf833981519152906001600160a01b0316611416823383612427565b61141f836126da565b505050565b61142c612692565b61143d6114388261435e565b6126f7565b6000606461145360a08401356040850135613fe2565b61145d9190613fc0565b90508060d260008460600135815260200190815260200160002060008282546114869190613ff9565b90915550600090506114a0610120840161010085016137aa565b6001600160a01b0316036115105760c9546114c6906001600160a01b03163330846128a9565b60006114d682604085013561400c565b11156115105760cf546115109033906001600160a01b03166114fc84604087013561400c565b60c9546001600160a01b03169291906128a9565b7f20cbd058e5b03c253185d3b0b90f21ef8b22a6f136ae092e54eafe62ab1f17cf61153e6020840184613857565b6040805167ffffffffffffffff1990921682528085013560208301520160405180910390a160cc546001600160a01b031663731133e9336060850135608086013561158d61012088018861401f565b6040518663ffffffff1660e01b81526004016115ad95949392919061436a565b600060405180830381600087803b1580156115c757600080fd5b505af11580156115db573d6000803e3d6000fd5b505050505050565b6001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016300361162b5760405162461bcd60e51b81526004016108d7906143b6565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316611674600080516020614578833981519152546001600160a01b031690565b6001600160a01b03161461169a5760405162461bcd60e51b81526004016108d790614402565b6116a381612914565b604080516000808252602082019092526116bf9183919061293b565b50565b60ce546000805160206145bf833981519152906001600160a01b03166116e9823383612427565b6116f1612aa6565b5050565b6116fd612692565b6117096114388361435e565b60c954611725906001600160a01b0316333060408601356128a9565b600061173082612af8565b9050611740818460400135612fbc565b7f20cbd058e5b03c253185d3b0b90f21ef8b22a6f136ae092e54eafe62ab1f17cf61176e6020850185613857565b6020808401516040805167ffffffffffffffff199094168452918301520160405180910390a160ca5460cf54602083015160405163a9059cbb60e01b81526001600160a01b039384169363a9059cbb936117cd93911691600401614209565b6020604051808303816000875af11580156117ec573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118109190614222565b5060cc546001600160a01b031663731133e9336060860135608087013561183b61012089018961401f565b6040518663ffffffff1660e01b815260040161185b95949392919061436a565b600060405180830381600087803b15801561187557600080fd5b505af1158015611889573d6000803e3d6000fd5b50505050505050565b60ce546000805160206145bf833981519152906001600160a01b03166118b9823383612427565b6118c4858585613002565b5050505050565b6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001630036119135760405162461bcd60e51b81526004016108d7906143b6565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031661195c600080516020614578833981519152546001600160a01b031690565b6001600160a01b0316146119825760405162461bcd60e51b81526004016108d790614402565b61198b82612914565b6116f18282600161293b565b6000306001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614611a375760405162461bcd60e51b815260206004820152603860248201527f555550535570677261646561626c653a206d757374206e6f742062652063616c60448201527f6c6564207468726f7567682064656c656761746563616c6c000000000000000060648201526084016108d7565b5060008051602061457883398151915290565b60ce546000805160206145bf833981519152906001600160a01b0316611a71823383612427565b611a7a836124be565b60cf80546001600160a01b0319166001600160a01b0385169081179091556040519081527f36f46b2bde32fbd885795815430d97ffbcbdb29ffce736e6efa650108517732f90602001610855565b60ce546000805160206145bf833981519152906001600160a01b0316611aef823383612427565b611af8836124be565b60cb80546001600160a01b0319166001600160a01b0385169081179091556040519081527f6e036931c74d1170fc27ca15ec63230c12dc68750f35e5aaa891ca3ca713111a90602001610855565b60ce546000805160206145bf833981519152906001600160a01b0316611b6d823383612427565b611b76836124be565b60cc80546001600160a01b0319166001600160a01b0385169081179091556040519081527fadf4f9c4625f28af2daf1bb6b7fd796f7057caed7dbcf05608c4a1e607cca8d190602001610855565b600054610100900460ff1615808015611be45750600054600160ff909116105b80611bfe5750303b158015611bfe575060005460ff166001145b611c615760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b60648201526084016108d7565b6000805460ff191660011790558015611c84576000805461ff0019166101001790555b611c8c613105565b8151611c97906124be565b611ca482602001516124be565b611cb182604001516124be565b611cbe82606001516124be565b611ccb8260a001516124be565b611cd88260c001516124be565b611ce582608001516124be565b611ced613134565b815160c980546001600160a01b03199081166001600160a01b0393841617909155602084015160ca80548316918416919091179055604084015160cb80548316918416919091179055608084015160cf80548316918416919091179055606084015160cc8054831691841691909117905560a084015160ce8054831691841691909117905560c084015160cd8054909216921691909117905580156116f1576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15050565b60ce546000805160206145bf833981519152906001600160a01b0316611df6823383612427565b611dff836124be565b60ce5460405163d547741f60e01b81527f442b28f9e83f97745ed75b067d0663bd985c0a386c9386d899cbbf5c7f42692760048201526001600160a01b0385811660248301529091169063d547741f90604401600060405180830381600087803b158015611e6c57600080fd5b505af1158015611e80573d6000803e3d6000fd5b505060c95460405163095ea7b360e01b81526001600160a01b03909116925063095ea7b39150611eb7908690600090600401614209565b6020604051808303816000875af1158015611ed6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611efa9190614222565b50505050565b60ce546000805160206145bf833981519152906001600160a01b0316611f27823383612427565b611f30836124be565b60ca5460405163095ea7b360e01b81526001600160a01b039091169063095ea7b390611eb790869060001990600401614209565b60ce546000805160206145bf833981519152906001600160a01b0316611f8b823383612427565b5050600091825260d2602052604090912055565b60ce546000805160206145bf833981519152906001600160a01b0316611fc6823383612427565b6116f161315b565b60ce546000805160206145bf833981519152906001600160a01b0316611ff5823383612427565b611ffe836124be565b60ce54604051632f2ff15d60e01b81527f442b28f9e83f97745ed75b067d0663bd985c0a386c9386d899cbbf5c7f42692760048201526001600160a01b03858116602483015290911690632f2ff15d90604401600060405180830381600087803b15801561206b57600080fd5b505af115801561207f573d6000803e3d6000fd5b505060c95460405163095ea7b360e01b81526001600160a01b03909116925063095ea7b39150611eb790869060001990600401614209565b60ce546000805160206145bf833981519152906001600160a01b03166120de823383612427565b6120e7836124be565b60ca80546001600160a01b0319166001600160a01b0385169081179091556040519081527f0a4ce1a2c865b0d2326b1515bb03bfb92994c47f88d096520215abd7f808824a90602001610855565b60ce546000805160206145bf833981519152906001600160a01b031661215c823383612427565b612165836124be565b505060d180546001600160a01b0319166001600160a01b0392909216919091179055565b612191612692565b60cd5460408051632b0c491b60e11b815290516000926001600160a01b03169163561892369160048083019260209291908290030181865afa1580156121db573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121ff919061410d565b905061228a60405180610160016040528085600001516001600160401b0319168152602001856020015164ffffffffff168152602001856040015181526020018381526020016001815260200160008152602001600081526020016000815260200160006001600160a01b0316815260200185610120015181526020018561014001518152506126f7565b60cf54604084015160c9546122b0926001600160a01b03918216923392909116906128a9565b60cd5460405163d0def52160e01b81526001600160a01b039091169063d0def521906122e2903390869060040161444e565b600060405180830381600087803b1580156122fc57600080fd5b505af1158015612310573d6000803e3d6000fd5b505050507f69578e4d7becfd7d2e3306dde750cd20e655b9b01f0eff48039271b19b636df63382604051610855929190614209565b60ce546000805160206145bf833981519152906001600160a01b031661236c823383612427565b60005b85811015611889578484828181106123895761238961428d565b9050602002013560d260008989858181106123a6576123a661428d565b90506020020135815260200190815260200160002060008282546123ca9190613ff9565b909155505060010161236f565b60ce546000805160206145bf833981519152906001600160a01b03166123fe823383612427565b600084815260d260205260408120805485929061241c908490613ff9565b909155505050505050565b604051632474521560e21b8152600481018490526001600160a01b0383811660248301528216906391d1485490604401602060405180830381865afa158015612474573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124989190614222565b61141f576040516301d4003760e61b8152600481018490523360248201526044016108d7565b6001600160a01b0381166116bf57604051631e7d738760e21b815260040160405180910390fd5b80516060808301516020808501516040805167ffffffffffffffff199096169286019290925290840191909152339183019190915264ffffffffff16608082015260009060a001604051602081830303815290604052905042826020015164ffffffffff16101561256957604051630819bdcd60e01b815260040160405180910390fd5b815167ffffffffffffffff1916600090815260d3602052604090205460ff16156125a657604051638baa579f60e01b815260040160405180910390fd5b60006125b6828460800151613198565b60ce54604051632474521560e21b81527f81d2ab4e362bdcb20cd7c861e0d022d10f4d86836828fdc77fc915bcf303a0c760048201526001600160a01b0380841660248301529293509116906391d1485490604401602060405180830381865afa158015612628573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061264c9190614222565b61266957604051638baa579f60e01b815260040160405180910390fd5b50505167ffffffffffffffff1916600090815260d360205260409020805460ff19166001179055565b60335460ff16156126d85760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b60448201526064016108d7565b565b60cf5460c9546116bf916001600160a01b0391821691168361327a565b60008160000151826020015133846040015185608001518660a001518760e001518861014001518960c001518a61010001516040516020016127429a99989796959493929190614472565b604051602081830303815290604052905042826020015164ffffffffff16101561277f57604051630819bdcd60e01b815260040160405180910390fd5b815167ffffffffffffffff1916600090815260d0602052604090205460ff16156127bc57604051638baa579f60e01b815260040160405180910390fd5b60006127cd82846101200151613198565b60ce54604051632474521560e21b81527f81d2ab4e362bdcb20cd7c861e0d022d10f4d86836828fdc77fc915bcf303a0c760048201526001600160a01b0380841660248301529293509116906391d1485490604401602060405180830381865afa15801561283f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128639190614222565b61288057604051638baa579f60e01b815260040160405180910390fd5b50505167ffffffffffffffff1916600090815260d060205260409020805460ff19166001179055565b6040516001600160a01b0380851660248301528316604482015260648101829052611efa9085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152613299565b60ce546000805160206145bf833981519152906001600160a01b031661141f823383612427565b7f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd91435460ff161561296e5761141f8361336e565b826001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa9250505080156129c8575060408051601f3d908101601f191682019092526129c59181019061410d565b60015b612a2b5760405162461bcd60e51b815260206004820152602e60248201527f45524331393637557067726164653a206e657720696d706c656d656e7461746960448201526d6f6e206973206e6f74205555505360901b60648201526084016108d7565b6000805160206145788339815191528114612a9a5760405162461bcd60e51b815260206004820152602960248201527f45524331393637557067726164653a20756e737570706f727465642070726f786044820152681a58589b195555525160ba1b60648201526084016108d7565b5061141f83838361340a565b612aae61342f565b6033805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b604080518082019091526000808252602082015260ca5460c95460ce546001600160a01b039283169291821691166391d148547f442b28f9e83f97745ed75b067d0663bd985c0a386c9386d899cbbf5c7f426927612b5c60408801602089016137aa565b6040516001600160e01b031960e085901b16815260048101929092526001600160a01b03166024820152604401602060405180830381865afa158015612ba6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612bca9190614222565b612be75760405163407df9a560e01b815260040160405180910390fd5b612bf460208501856137aa565b6001600160a01b0316612c0d60408601602087016137aa565b6001600160a01b031614612c9c576001600160a01b03811663095ea7b3612c3760208701876137aa565b6000196040518363ffffffff1660e01b8152600401612c57929190614209565b6020604051808303816000875af1158015612c76573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c9a9190614222565b505b6040516370a0823160e01b81523060048201526000906001600160a01b038416906370a0823190602401602060405180830381865afa158015612ce3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d07919061410d565b6040516370a0823160e01b81523060048201529091506000906001600160a01b038416906370a0823190602401602060405180830381865afa158015612d51573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d75919061410d565b90506000612d8960408801602089016137aa565b6001600160a01b0316612d9f604089018961401f565b604051612dad9291906144ed565b6000604051808303816000865af19150503d8060008114612dea576040519150601f19603f3d011682016040523d82523d6000602084013e612def565b606091505b5050905080612e1157604051634ae3726760e11b815260040160405180910390fd5b6040516370a0823160e01b815230600482015283906001600160a01b038716906370a0823190602401602060405180830381865afa158015612e57573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e7b919061410d565b612e85919061400c565b60208701526040516370a0823160e01b81523060048201526001600160a01b038516906370a0823190602401602060405180830381865afa158015612ece573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ef2919061410d565b612efc908361400c565b8652612f0b60208801886137aa565b6001600160a01b0316612f246040890160208a016137aa565b6001600160a01b031614612fb2576001600160a01b03841663095ea7b3612f4e60208a018a6137aa565b60006040518363ffffffff1660e01b8152600401612f6d929190614209565b6020604051808303816000875af1158015612f8c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612fb09190614222565b505b5050505050919050565b81518114612fdd576040516345dc30ff60e11b815260040160405180910390fd5b60008260200151116116f157604051631e83c98b60e31b815260040160405180910390fd5b600080846001600160a01b031663a9059cbb60e01b858560405160240161302a929190614209565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b031990941693909317909252905161306891906144fd565b6000604051808303816000865af19150503d80600081146130a5576040519150601f19603f3d011682016040523d82523d6000602084013e6130aa565b606091505b50915091508180156130d45750805115806130d45750808060200190518101906130d49190614222565b6118c45760405162461bcd60e51b815260206004820152600260248201526114d560f21b60448201526064016108d7565b600054610100900460ff1661312c5760405162461bcd60e51b81526004016108d790614519565b6126d8613478565b600054610100900460ff166126d85760405162461bcd60e51b81526004016108d790614519565b613163612692565b6033805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258612adb3390565b6000806131f984805190602001206040517f19457468657265756d205369676e6564204d6573736167653a0a3332000000006020820152603c8101829052600090605c01604051602081830303815290604052805190602001209050919050565b90506000806000613209866134ab565b60408051600081526020810180835289905260ff8316918101919091526060810184905260808101839052929550909350915060019060a0016020604051602081039080840390855afa158015613264573d6000803e3d6000fd5b5050604051601f19015198975050505050505050565b61141f8363a9059cbb60e01b84846040516024016128dd929190614209565b60006132ee826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661351f9092919063ffffffff16565b905080516000148061330f57508080602001905181019061330f9190614222565b61141f5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016108d7565b6001600160a01b0381163b6133db5760405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b60648201526084016108d7565b60008051602061457883398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b61341383613536565b6000825111806134205750805b1561141f57611efa8383613576565b60335460ff166126d85760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b60448201526064016108d7565b600054610100900460ff1661349f5760405162461bcd60e51b81526004016108d790614519565b6033805460ff19169055565b600080600083516041146135015760405162461bcd60e51b815260206004820152601d60248201527f5369673a20496e76616c6964207369676e6174757265206c656e67746800000060448201526064016108d7565b50505060208101516040820151606090920151909260009190911a90565b606061352e84846000856135a4565b949350505050565b61353f8161336e565b6040516001600160a01b038216907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a250565b606061359b83836040518060600160405280602781526020016145986027913961367f565b90505b92915050565b6060824710156136055760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b60648201526084016108d7565b600080866001600160a01b0316858760405161362191906144fd565b60006040518083038185875af1925050503d806000811461365e576040519150601f19603f3d011682016040523d82523d6000602084013e613663565b606091505b5091509150613674878383876136f7565b979650505050505050565b6060600080856001600160a01b03168560405161369c91906144fd565b600060405180830381855af49150503d80600081146136d7576040519150601f19603f3d011682016040523d82523d6000602084013e6136dc565b606091505b50915091506136ed868383876136f7565b9695505050505050565b6060831561376657825160000361375f576001600160a01b0385163b61375f5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016108d7565b508161352e565b61352e838381511561377b5781518083602001fd5b8060405162461bcd60e51b81526004016108d79190614564565b6001600160a01b03811681146116bf57600080fd5b6000602082840312156137bc57600080fd5b81356137c781613795565b9392505050565b80356137d981613795565b919050565b6000806000606084860312156137f357600080fd5b83356001600160401b0381111561380957600080fd5b8401610100818703121561381c57600080fd5b925060208401359150604084013561383381613795565b809150509250925092565b803567ffffffffffffffff19811681146137d957600080fd5b60006020828403121561386957600080fd5b61359b8261383e565b60006020828403121561388457600080fd5b81356001600160401b0381111561389a57600080fd5b820160a081850312156137c757600080fd5b6000602082840312156138be57600080fd5b81356001600160401b038111156138d457600080fd5b8201604081850312156137c757600080fd5b6000602082840312156138f857600080fd5b5035919050565b6000610160828403121561391257600080fd5b50919050565b60006020828403121561392a57600080fd5b81356001600160401b0381111561394057600080fd5b61352e848285016138ff565b6000806040838503121561395f57600080fd5b82356001600160401b038082111561397657600080fd5b613982868387016138ff565b9350602085013591508082111561399857600080fd5b508301606081860312156139ab57600080fd5b809150509250929050565b6000806000606084860312156139cb57600080fd5b83356139d681613795565b925060208401356139e681613795565b929592945050506040919091013590565b634e487b7160e01b600052604160045260246000fd5b60405161016081016001600160401b0381118282101715613a3057613a306139f7565b60405290565b604051601f8201601f191681016001600160401b0381118282101715613a5e57613a5e6139f7565b604052919050565b60006001600160401b03831115613a7f57613a7f6139f7565b613a92601f8401601f1916602001613a36565b9050828152838383011115613aa657600080fd5b828260208301376000602084830101529392505050565b600082601f830112613ace57600080fd5b61359b83833560208501613a66565b60008060408385031215613af057600080fd5b8235613afb81613795565b915060208301356001600160401b03811115613b1657600080fd5b613b2285828601613abd565b9150509250929050565b600060e08284031215613b3e57600080fd5b60405160e081018181106001600160401b0382111715613b6057613b606139f7565b6040528235613b6e81613795565b81526020830135613b7e81613795565b60208201526040830135613b9181613795565b60408201526060830135613ba481613795565b6060820152613bb5608084016137ce565b6080820152613bc660a084016137ce565b60a0820152613bd760c084016137ce565b60c08201529392505050565b60008060408385031215613bf657600080fd5b50508035926020909101359150565b600082601f830112613c1657600080fd5b813560206001600160401b03821115613c3157613c316139f7565b8160051b613c40828201613a36565b9283528481018201928281019087851115613c5a57600080fd5b83870192505b8483101561367457823582529183019190830190613c60565b600080600080600060a08688031215613c9157600080fd5b8535613c9c81613795565b94506020860135613cac81613795565b935060408601356001600160401b0380821115613cc857600080fd5b613cd489838a01613c05565b94506060880135915080821115613cea57600080fd5b613cf689838a01613c05565b93506080880135915080821115613d0c57600080fd5b50613d1988828901613abd565b9150509295509295909350565b803564ffffffffff811681146137d957600080fd5b60006101608284031215613d4e57600080fd5b613d56613a0d565b9050613d618261383e565b8152613d6f60208301613d26565b602082015260408201356040820152606082013560608201526080820135608082015260a082013560a082015260c082013560c082015260e082013560e0820152610100613dbe8184016137ce565b90820152610120828101356001600160401b0380821115613dde57600080fd5b613dea86838701613abd565b83850152610140925082850135915080821115613e0657600080fd5b50613e1385828601613abd565b82840152505092915050565b60008060408385031215613e3257600080fd5b82356001600160401b0380821115613e4957600080fd5b613e5586838701613d3b565b93506020850135915080821115613e6b57600080fd5b508301601f81018513613e7d57600080fd5b613b2285823560208401613a66565b60008083601f840112613e9e57600080fd5b5081356001600160401b03811115613eb557600080fd5b6020830191508360208260051b8501011115613ed057600080fd5b9250929050565b60008060008060408587031215613eed57600080fd5b84356001600160401b0380821115613f0457600080fd5b613f1088838901613e8c565b90965094506020870135915080821115613f2957600080fd5b50613f3687828801613e8c565b95989497509550505050565b600080600080600060a08688031215613f5a57600080fd5b8535613f6581613795565b94506020860135613f7581613795565b9350604086013592506060860135915060808601356001600160401b03811115613f9e57600080fd5b613d1988828901613abd565b634e487b7160e01b600052601160045260246000fd5b600082613fdd57634e487b7160e01b600052601260045260246000fd5b500490565b808202811582820484141761359e5761359e613faa565b8082018082111561359e5761359e613faa565b8181038181111561359e5761359e613faa565b6000808335601e1984360301811261403657600080fd5b8301803591506001600160401b0382111561405057600080fd5b602001915036819003821315613ed057600080fd5b60005b83811015614080578181015183820152602001614068565b50506000910152565b600081518084526140a1816020860160208601614065565b601f01601f19169290920160200192915050565b602081526000825160a060208401526140d160c0840182614089565b905060018060a01b0360208501511660408401526040840151606084015260608401516080840152608084015160a08401528091505092915050565b60006020828403121561411f57600080fd5b5051919050565b60208082526021908201527f53616c65734d616e616765723a207377617020616d6f756e7420746f6f206c6f6040820152607760f81b606082015260800190565b600060a0823603121561417957600080fd5b60405160a081016001600160401b03828210818311171561419c5761419c6139f7565b816040526141a98561383e565b83526141b760208601613d26565b6020840152604085013591506141cc82613795565b8160408401526060850135606084015260808501359150808211156141f057600080fd5b506141fd36828601613abd565b60808301525092915050565b6001600160a01b03929092168252602082015260400190565b60006020828403121561423457600080fd5b815180151581146137c757600080fd5b6000808335601e1984360301811261425b57600080fd5b8301803591506001600160401b0382111561427557600080fd5b602001915061012081023603821315613ed057600080fd5b634e487b7160e01b600052603260045260246000fd5b600081518084526020808501945080840160005b838110156142d3578151875295820195908201906001016142b7565b509495945050505050565b6001600160a01b0384168152608060208201819052600090614302908301856142a3565b828103604084015261431481856142a3565b8381036060909401939093525050600081526020019392505050565b60408152600061434360408301856142a3565b828103602084015261435581856142a3565b95945050505050565b600061359e3683613d3b565b60018060a01b038616815284602082015283604082015260806060820152816080820152818360a0830137600081830160a090810191909152601f909201601f19160101949350505050565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b19195b1959d85d1958d85b1b60a21b606082015260800190565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b6163746976652070726f787960a01b606082015260800190565b6001600160a01b038316815260406020820181905260009061352e90830184614089565b60006101406001600160401b03198d16835264ffffffffff8c16602084015260018060a01b03808c1660408501528a60608501528960808501528860a08501528760c08501528160e08501526144ca82850188614089565b92508561010085015280851661012085015250509b9a5050505050505050505050565b8183823760009101908152919050565b6000825161450f818460208701614065565b9190910192915050565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b60208152600061359b602083018461408956fe360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564396cc212fb89072d8d9db8917ca50a364cf7dabc0b5420a8e675bd1b9082bed3a26469706673582212207d2c2813e57b312af083884247fc2146f764006199be563da58c9b9fb22939c364736f6c63430008110033

Deployed Bytecode

0x60806040526004361061024a5760003560e01c80635b769f3c116101395780638c388a9d116100b6578063e83a5a551161007a578063e83a5a55146106f2578063e93032091461071f578063ef6318831461073f578063f23a6e611461075f578063f69296de1461078b578063ff0ad417146107ab57600080fd5b80638c388a9d1461062d578063b3e089a21461064d578063bc197c811461066d578063bea9849e146106b2578063c5e7be6d146106d257600080fd5b80636e105749116100fd5780636e105749146105985780636e7641a2146105b8578063742267df146105d85780637ded4b79146105f85780638456cb591461061857600080fd5b80635b769f3c146105005780635c975abb146105205780635ea7a11d146105385780635f48e4271461055857806367d5f3371461057857600080fd5b80632e1a7d4d116101c757806344004cc11161018b57806344004cc11461046a5780634dc32eff1461048a5780634f1ef286146104aa57806352d1902d146104bd5780635699517c146104e057600080fd5b80632e1a7d4d146103d557806330d75ba3146103f55780633659cfe6146104155780633f4ba83a14610435578063414fb4251461044a57600080fd5b80630f11f4e71161020e5780630f11f4e71461031557806319f2e4fc146103355780632432a9511461037557806325c855e4146103955780632b838d1b146103b557600080fd5b80630255a03b14610256578063060f958614610278578063077e2063146102b55780630af2a89b146102d55780630af88b24146102f557600080fd5b3661025157005b600080fd5b34801561026257600080fd5b506102766102713660046137aa565b6107db565b005b34801561028457600080fd5b5060c954610298906001600160a01b031681565b6040516001600160a01b0390911681526020015b60405180910390f35b3480156102c157600080fd5b506102766102d03660046137de565b610862565b3480156102e157600080fd5b5060ce54610298906001600160a01b031681565b34801561030157600080fd5b5060cb54610298906001600160a01b031681565b34801561032157600080fd5b5060cc54610298906001600160a01b031681565b34801561034157600080fd5b50610365610350366004613857565b60d36020526000908152604090205460ff1681565b60405190151581526020016102ac565b34801561038157600080fd5b506102766103903660046137aa565b610b50565b3480156103a157600080fd5b506102766103b0366004613872565b610bce565b3480156103c157600080fd5b506102766103d03660046138ac565b610cb7565b3480156103e157600080fd5b506102766103f03660046138e6565b6113ef565b34801561040157600080fd5b50610276610410366004613918565b611424565b34801561042157600080fd5b506102766104303660046137aa565b6115e3565b34801561044157600080fd5b506102766116c2565b34801561045657600080fd5b5061027661046536600461394c565b6116f5565b34801561047657600080fd5b506102766104853660046139b6565b611892565b34801561049657600080fd5b5060d154610298906001600160a01b031681565b6102766104b8366004613add565b6118cb565b3480156104c957600080fd5b506104d2611997565b6040519081526020016102ac565b3480156104ec57600080fd5b506102766104fb3660046137aa565b611a4a565b34801561050c57600080fd5b5061027661051b3660046137aa565b611ac8565b34801561052c57600080fd5b5060335460ff16610365565b34801561054457600080fd5b5060cf54610298906001600160a01b031681565b34801561056457600080fd5b506102766105733660046137aa565b611b46565b34801561058457600080fd5b50610276610593366004613b2c565b611bc4565b3480156105a457600080fd5b5060cd54610298906001600160a01b031681565b3480156105c457600080fd5b506102766105d33660046137aa565b611dcf565b3480156105e457600080fd5b506102766105f33660046137aa565b611f00565b34801561060457600080fd5b50610276610613366004613be3565b611f64565b34801561062457600080fd5b50610276611f9f565b34801561063957600080fd5b506102766106483660046137aa565b611fce565b34801561065957600080fd5b506102766106683660046137aa565b6120b7565b34801561067957600080fd5b50610699610688366004613c79565b63bc197c8160e01b95945050505050565b6040516001600160e01b031990911681526020016102ac565b3480156106be57600080fd5b506102766106cd3660046137aa565b612135565b3480156106de57600080fd5b506102766106ed366004613e1f565b612189565b3480156106fe57600080fd5b506104d261070d3660046138e6565b60d26020526000908152604090205481565b34801561072b57600080fd5b5060ca54610298906001600160a01b031681565b34801561074b57600080fd5b5061027661075a366004613ed7565b612345565b34801561076b57600080fd5b5061069961077a366004613f42565b63f23a6e6160e01b95945050505050565b34801561079757600080fd5b506102766107a6366004613be3565b6123d7565b3480156107b757600080fd5b506103656107c6366004613857565b60d06020526000908152604090205460ff1681565b60ce546000805160206145bf833981519152906001600160a01b0316610802823383612427565b61080b836124be565b60c980546001600160a01b0319166001600160a01b0385169081179091556040519081527f25a6b3bbb8afcb2bda3493ac1c231ce7bfc7de5d124a241d745dd3e47eb0dc44906020015b60405180910390a1505050565b60cc546001600160a01b031633146108e05760405162461bcd60e51b815260206004820152603660248201527f53616c65734d616e616765723a206f6e6c79204e465420636f6e74726163742060448201527531b0b71031b0b636103a3434b990333ab731ba34b7b760511b60648201526084015b60405180910390fd5b8235600090815260d260205260408120546108fc908490613fc0565b9050600061090e602086013583613fe2565b905060006064610922606088013584613fe2565b61092c9190613fc0565b905060006064610940604089013585613fe2565b61094a9190613fc0565b905060006109588284613ff9565b8835600090815260d2602052604081208054929350869290919061097d90849061400c565b90915550506040805160a081019091526000908061099e60e08c018c61401f565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201829052509385525050306020840152504260408084019190915260808d810135606085015290920181905260d154915163c04b8d5960e01b8152929350916001600160a01b039091169063c04b8d5990610a289085906004016140b5565b6020604051808303816000875af1158015610a47573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a6b919061410d565b905082811015610a8d5760405162461bcd60e51b81526004016108d790614126565b60c954604051630852cd8d60e31b8152600481018890526001600160a01b03909116906342966c6890602401600060405180830381600087803b158015610ad357600080fd5b505af1158015610ae7573d6000803e3d6000fd5b5050604080518d3581526020808f0135908201528d820135818301526001600160a01b038c16606082015290518793508992507f2ed5ae033d5e06c4036702046608787d0457d99dac8bf7e6f6dfcdb6402ace7d9181900360800190a350505050505050505050565b60ce546000805160206145bf833981519152906001600160a01b0316610b77823383612427565b610b80836124be565b60cd80546001600160a01b0319166001600160a01b0385169081179091556040519081527f3409e1dd669c1b9bba4e12677a0324b44dfb4943c62570d7b18215b74bd880fd90602001610855565b610bdf610bda82614167565b6124e5565b60c95460405163a9059cbb60e01b81526001600160a01b039091169063a9059cbb90610c15903390606086013590600401614209565b6020604051808303816000875af1158015610c34573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c589190614222565b507fcf0889de76897114c9424de6273503db7d78aea38e623201dca2f510feba8dd8610c876020830183613857565b6040805167ffffffffffffffff19929092168252336020830152606084810135838301529051918290030190a150565b610cbf612692565b60ce547f81d2ab4e362bdcb20cd7c861e0d022d10f4d86836828fdc77fc915bcf303a0c7906001600160a01b0316610cf8823383612427565b6000610d048480614244565b90506001600160401b03811115610d1d57610d1d6139f7565b604051908082528060200260200182016040528015610d46578160200160208202803683370190505b5090506000610d558580614244565b90506001600160401b03811115610d6e57610d6e6139f7565b604051908082528060200260200182016040528015610d97578160200160208202803683370190505b50905060005b610da78680614244565b905081101561125b5760006064610dbe8880614244565b84818110610dce57610dce61428d565b9050610120020160800135888060000190610de99190614244565b85818110610df957610df961428d565b9050610120020160200135610e0e9190613fe2565b610e189190613fc0565b90508060d26000610e298a80614244565b86818110610e3957610e3961428d565b905061012002016040013581526020019081526020016000206000828254610e619190613ff9565b90915550600090506064610e758980614244565b85818110610e8557610e8561428d565b9050610120020160a0013583610e9b9190613fe2565b610ea59190613fc0565b905060006040518060a001604052808a8060200190610ec4919061401f565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250505090825250306020820152426040820152606001610f148b80614244565b87818110610f2457610f2461428d565b9050610120020160e00135815260200160008152509050600060d160009054906101000a90046001600160a01b03166001600160a01b031663c04b8d59836040518263ffffffff1660e01b8152600401610f7e91906140b5565b6020604051808303816000875af1158015610f9d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fc1919061410d565b90506064610fcf8b80614244565b87818110610fdf57610fdf61428d565b9050610120020160c0013585610ff59190613fe2565b610fff9190613fc0565b6110099084613ff9565b8110156110285760405162461bcd60e51b81526004016108d790614126565b60c954604051630852cd8d60e31b8152600481018390526001600160a01b03909116906342966c6890602401600060405180830381600087803b15801561106e57600080fd5b505af1158015611082573d6000803e3d6000fd5b5061109392508c9150819050614244565b868181106110a3576110a361428d565b90506101200201604001358786815181106110c0576110c061428d565b60209081029190910101526110d58a80614244565b868181106110e5576110e561428d565b90506101200201606001358686815181106111025761110261428d565b602090810291909101015260646111198b80614244565b878181106111295761112961428d565b9050610120020160c001358561113f9190613fe2565b6111499190613fc0565b847f2ed5ae033d5e06c4036702046608787d0457d99dac8bf7e6f6dfcdb6402ace7d6111758d80614244565b898181106111855761118561428d565b90506101200201604001358d80600001906111a09190614244565b8a8181106111b0576111b061428d565b90506101200201606001358e80600001906111cb9190614244565b8b8181106111db576111db61428d565b9050610120020160c001358f80600001906111f69190614244565b8c8181106112065761120661428d565b9050610120020161010001602081019061122091906137aa565b604080519485526020850193909352918301526001600160a01b0316606082015260800160405180910390a384600101945050505050610d9d565b5060cc54604051630fbfeffd60e11b81526001600160a01b0390911690631f7fdffa90611290903090869086906004016142de565b600060405180830381600087803b1580156112aa57600080fd5b505af11580156112be573d6000803e3d6000fd5b5050505060005b6112cf8680614244565b9050811015611383577f20cbd058e5b03c253185d3b0b90f21ef8b22a6f136ae092e54eafe62ab1f17cf6113038780614244565b838181106113135761131361428d565b61132a926020610120909202019081019150613857565b6113348880614244565b848181106113445761134461428d565b905061012002016020013560405161137392919067ffffffffffffffff19929092168252602082015260400190565b60405180910390a16001016112c5565b5060cc5460405163f611c48160e01b81526001600160a01b039091169063f611c481906113b69085908590600401614330565b600060405180830381600087803b1580156113d057600080fd5b505af11580156113e4573d6000803e3d6000fd5b505050505050505050565b60ce546000805160206145bf833981519152906001600160a01b0316611416823383612427565b61141f836126da565b505050565b61142c612692565b61143d6114388261435e565b6126f7565b6000606461145360a08401356040850135613fe2565b61145d9190613fc0565b90508060d260008460600135815260200190815260200160002060008282546114869190613ff9565b90915550600090506114a0610120840161010085016137aa565b6001600160a01b0316036115105760c9546114c6906001600160a01b03163330846128a9565b60006114d682604085013561400c565b11156115105760cf546115109033906001600160a01b03166114fc84604087013561400c565b60c9546001600160a01b03169291906128a9565b7f20cbd058e5b03c253185d3b0b90f21ef8b22a6f136ae092e54eafe62ab1f17cf61153e6020840184613857565b6040805167ffffffffffffffff1990921682528085013560208301520160405180910390a160cc546001600160a01b031663731133e9336060850135608086013561158d61012088018861401f565b6040518663ffffffff1660e01b81526004016115ad95949392919061436a565b600060405180830381600087803b1580156115c757600080fd5b505af11580156115db573d6000803e3d6000fd5b505050505050565b6001600160a01b037f00000000000000000000000044bea25aac16a73112239bb7c222757bbeb3582116300361162b5760405162461bcd60e51b81526004016108d7906143b6565b7f00000000000000000000000044bea25aac16a73112239bb7c222757bbeb358216001600160a01b0316611674600080516020614578833981519152546001600160a01b031690565b6001600160a01b03161461169a5760405162461bcd60e51b81526004016108d790614402565b6116a381612914565b604080516000808252602082019092526116bf9183919061293b565b50565b60ce546000805160206145bf833981519152906001600160a01b03166116e9823383612427565b6116f1612aa6565b5050565b6116fd612692565b6117096114388361435e565b60c954611725906001600160a01b0316333060408601356128a9565b600061173082612af8565b9050611740818460400135612fbc565b7f20cbd058e5b03c253185d3b0b90f21ef8b22a6f136ae092e54eafe62ab1f17cf61176e6020850185613857565b6020808401516040805167ffffffffffffffff199094168452918301520160405180910390a160ca5460cf54602083015160405163a9059cbb60e01b81526001600160a01b039384169363a9059cbb936117cd93911691600401614209565b6020604051808303816000875af11580156117ec573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118109190614222565b5060cc546001600160a01b031663731133e9336060860135608087013561183b61012089018961401f565b6040518663ffffffff1660e01b815260040161185b95949392919061436a565b600060405180830381600087803b15801561187557600080fd5b505af1158015611889573d6000803e3d6000fd5b50505050505050565b60ce546000805160206145bf833981519152906001600160a01b03166118b9823383612427565b6118c4858585613002565b5050505050565b6001600160a01b037f00000000000000000000000044bea25aac16a73112239bb7c222757bbeb358211630036119135760405162461bcd60e51b81526004016108d7906143b6565b7f00000000000000000000000044bea25aac16a73112239bb7c222757bbeb358216001600160a01b031661195c600080516020614578833981519152546001600160a01b031690565b6001600160a01b0316146119825760405162461bcd60e51b81526004016108d790614402565b61198b82612914565b6116f18282600161293b565b6000306001600160a01b037f00000000000000000000000044bea25aac16a73112239bb7c222757bbeb358211614611a375760405162461bcd60e51b815260206004820152603860248201527f555550535570677261646561626c653a206d757374206e6f742062652063616c60448201527f6c6564207468726f7567682064656c656761746563616c6c000000000000000060648201526084016108d7565b5060008051602061457883398151915290565b60ce546000805160206145bf833981519152906001600160a01b0316611a71823383612427565b611a7a836124be565b60cf80546001600160a01b0319166001600160a01b0385169081179091556040519081527f36f46b2bde32fbd885795815430d97ffbcbdb29ffce736e6efa650108517732f90602001610855565b60ce546000805160206145bf833981519152906001600160a01b0316611aef823383612427565b611af8836124be565b60cb80546001600160a01b0319166001600160a01b0385169081179091556040519081527f6e036931c74d1170fc27ca15ec63230c12dc68750f35e5aaa891ca3ca713111a90602001610855565b60ce546000805160206145bf833981519152906001600160a01b0316611b6d823383612427565b611b76836124be565b60cc80546001600160a01b0319166001600160a01b0385169081179091556040519081527fadf4f9c4625f28af2daf1bb6b7fd796f7057caed7dbcf05608c4a1e607cca8d190602001610855565b600054610100900460ff1615808015611be45750600054600160ff909116105b80611bfe5750303b158015611bfe575060005460ff166001145b611c615760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b60648201526084016108d7565b6000805460ff191660011790558015611c84576000805461ff0019166101001790555b611c8c613105565b8151611c97906124be565b611ca482602001516124be565b611cb182604001516124be565b611cbe82606001516124be565b611ccb8260a001516124be565b611cd88260c001516124be565b611ce582608001516124be565b611ced613134565b815160c980546001600160a01b03199081166001600160a01b0393841617909155602084015160ca80548316918416919091179055604084015160cb80548316918416919091179055608084015160cf80548316918416919091179055606084015160cc8054831691841691909117905560a084015160ce8054831691841691909117905560c084015160cd8054909216921691909117905580156116f1576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15050565b60ce546000805160206145bf833981519152906001600160a01b0316611df6823383612427565b611dff836124be565b60ce5460405163d547741f60e01b81527f442b28f9e83f97745ed75b067d0663bd985c0a386c9386d899cbbf5c7f42692760048201526001600160a01b0385811660248301529091169063d547741f90604401600060405180830381600087803b158015611e6c57600080fd5b505af1158015611e80573d6000803e3d6000fd5b505060c95460405163095ea7b360e01b81526001600160a01b03909116925063095ea7b39150611eb7908690600090600401614209565b6020604051808303816000875af1158015611ed6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611efa9190614222565b50505050565b60ce546000805160206145bf833981519152906001600160a01b0316611f27823383612427565b611f30836124be565b60ca5460405163095ea7b360e01b81526001600160a01b039091169063095ea7b390611eb790869060001990600401614209565b60ce546000805160206145bf833981519152906001600160a01b0316611f8b823383612427565b5050600091825260d2602052604090912055565b60ce546000805160206145bf833981519152906001600160a01b0316611fc6823383612427565b6116f161315b565b60ce546000805160206145bf833981519152906001600160a01b0316611ff5823383612427565b611ffe836124be565b60ce54604051632f2ff15d60e01b81527f442b28f9e83f97745ed75b067d0663bd985c0a386c9386d899cbbf5c7f42692760048201526001600160a01b03858116602483015290911690632f2ff15d90604401600060405180830381600087803b15801561206b57600080fd5b505af115801561207f573d6000803e3d6000fd5b505060c95460405163095ea7b360e01b81526001600160a01b03909116925063095ea7b39150611eb790869060001990600401614209565b60ce546000805160206145bf833981519152906001600160a01b03166120de823383612427565b6120e7836124be565b60ca80546001600160a01b0319166001600160a01b0385169081179091556040519081527f0a4ce1a2c865b0d2326b1515bb03bfb92994c47f88d096520215abd7f808824a90602001610855565b60ce546000805160206145bf833981519152906001600160a01b031661215c823383612427565b612165836124be565b505060d180546001600160a01b0319166001600160a01b0392909216919091179055565b612191612692565b60cd5460408051632b0c491b60e11b815290516000926001600160a01b03169163561892369160048083019260209291908290030181865afa1580156121db573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121ff919061410d565b905061228a60405180610160016040528085600001516001600160401b0319168152602001856020015164ffffffffff168152602001856040015181526020018381526020016001815260200160008152602001600081526020016000815260200160006001600160a01b0316815260200185610120015181526020018561014001518152506126f7565b60cf54604084015160c9546122b0926001600160a01b03918216923392909116906128a9565b60cd5460405163d0def52160e01b81526001600160a01b039091169063d0def521906122e2903390869060040161444e565b600060405180830381600087803b1580156122fc57600080fd5b505af1158015612310573d6000803e3d6000fd5b505050507f69578e4d7becfd7d2e3306dde750cd20e655b9b01f0eff48039271b19b636df63382604051610855929190614209565b60ce546000805160206145bf833981519152906001600160a01b031661236c823383612427565b60005b85811015611889578484828181106123895761238961428d565b9050602002013560d260008989858181106123a6576123a661428d565b90506020020135815260200190815260200160002060008282546123ca9190613ff9565b909155505060010161236f565b60ce546000805160206145bf833981519152906001600160a01b03166123fe823383612427565b600084815260d260205260408120805485929061241c908490613ff9565b909155505050505050565b604051632474521560e21b8152600481018490526001600160a01b0383811660248301528216906391d1485490604401602060405180830381865afa158015612474573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124989190614222565b61141f576040516301d4003760e61b8152600481018490523360248201526044016108d7565b6001600160a01b0381166116bf57604051631e7d738760e21b815260040160405180910390fd5b80516060808301516020808501516040805167ffffffffffffffff199096169286019290925290840191909152339183019190915264ffffffffff16608082015260009060a001604051602081830303815290604052905042826020015164ffffffffff16101561256957604051630819bdcd60e01b815260040160405180910390fd5b815167ffffffffffffffff1916600090815260d3602052604090205460ff16156125a657604051638baa579f60e01b815260040160405180910390fd5b60006125b6828460800151613198565b60ce54604051632474521560e21b81527f81d2ab4e362bdcb20cd7c861e0d022d10f4d86836828fdc77fc915bcf303a0c760048201526001600160a01b0380841660248301529293509116906391d1485490604401602060405180830381865afa158015612628573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061264c9190614222565b61266957604051638baa579f60e01b815260040160405180910390fd5b50505167ffffffffffffffff1916600090815260d360205260409020805460ff19166001179055565b60335460ff16156126d85760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b60448201526064016108d7565b565b60cf5460c9546116bf916001600160a01b0391821691168361327a565b60008160000151826020015133846040015185608001518660a001518760e001518861014001518960c001518a61010001516040516020016127429a99989796959493929190614472565b604051602081830303815290604052905042826020015164ffffffffff16101561277f57604051630819bdcd60e01b815260040160405180910390fd5b815167ffffffffffffffff1916600090815260d0602052604090205460ff16156127bc57604051638baa579f60e01b815260040160405180910390fd5b60006127cd82846101200151613198565b60ce54604051632474521560e21b81527f81d2ab4e362bdcb20cd7c861e0d022d10f4d86836828fdc77fc915bcf303a0c760048201526001600160a01b0380841660248301529293509116906391d1485490604401602060405180830381865afa15801561283f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128639190614222565b61288057604051638baa579f60e01b815260040160405180910390fd5b50505167ffffffffffffffff1916600090815260d060205260409020805460ff19166001179055565b6040516001600160a01b0380851660248301528316604482015260648101829052611efa9085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152613299565b60ce546000805160206145bf833981519152906001600160a01b031661141f823383612427565b7f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd91435460ff161561296e5761141f8361336e565b826001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa9250505080156129c8575060408051601f3d908101601f191682019092526129c59181019061410d565b60015b612a2b5760405162461bcd60e51b815260206004820152602e60248201527f45524331393637557067726164653a206e657720696d706c656d656e7461746960448201526d6f6e206973206e6f74205555505360901b60648201526084016108d7565b6000805160206145788339815191528114612a9a5760405162461bcd60e51b815260206004820152602960248201527f45524331393637557067726164653a20756e737570706f727465642070726f786044820152681a58589b195555525160ba1b60648201526084016108d7565b5061141f83838361340a565b612aae61342f565b6033805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b604080518082019091526000808252602082015260ca5460c95460ce546001600160a01b039283169291821691166391d148547f442b28f9e83f97745ed75b067d0663bd985c0a386c9386d899cbbf5c7f426927612b5c60408801602089016137aa565b6040516001600160e01b031960e085901b16815260048101929092526001600160a01b03166024820152604401602060405180830381865afa158015612ba6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612bca9190614222565b612be75760405163407df9a560e01b815260040160405180910390fd5b612bf460208501856137aa565b6001600160a01b0316612c0d60408601602087016137aa565b6001600160a01b031614612c9c576001600160a01b03811663095ea7b3612c3760208701876137aa565b6000196040518363ffffffff1660e01b8152600401612c57929190614209565b6020604051808303816000875af1158015612c76573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c9a9190614222565b505b6040516370a0823160e01b81523060048201526000906001600160a01b038416906370a0823190602401602060405180830381865afa158015612ce3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d07919061410d565b6040516370a0823160e01b81523060048201529091506000906001600160a01b038416906370a0823190602401602060405180830381865afa158015612d51573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d75919061410d565b90506000612d8960408801602089016137aa565b6001600160a01b0316612d9f604089018961401f565b604051612dad9291906144ed565b6000604051808303816000865af19150503d8060008114612dea576040519150601f19603f3d011682016040523d82523d6000602084013e612def565b606091505b5050905080612e1157604051634ae3726760e11b815260040160405180910390fd5b6040516370a0823160e01b815230600482015283906001600160a01b038716906370a0823190602401602060405180830381865afa158015612e57573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e7b919061410d565b612e85919061400c565b60208701526040516370a0823160e01b81523060048201526001600160a01b038516906370a0823190602401602060405180830381865afa158015612ece573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ef2919061410d565b612efc908361400c565b8652612f0b60208801886137aa565b6001600160a01b0316612f246040890160208a016137aa565b6001600160a01b031614612fb2576001600160a01b03841663095ea7b3612f4e60208a018a6137aa565b60006040518363ffffffff1660e01b8152600401612f6d929190614209565b6020604051808303816000875af1158015612f8c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612fb09190614222565b505b5050505050919050565b81518114612fdd576040516345dc30ff60e11b815260040160405180910390fd5b60008260200151116116f157604051631e83c98b60e31b815260040160405180910390fd5b600080846001600160a01b031663a9059cbb60e01b858560405160240161302a929190614209565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b031990941693909317909252905161306891906144fd565b6000604051808303816000865af19150503d80600081146130a5576040519150601f19603f3d011682016040523d82523d6000602084013e6130aa565b606091505b50915091508180156130d45750805115806130d45750808060200190518101906130d49190614222565b6118c45760405162461bcd60e51b815260206004820152600260248201526114d560f21b60448201526064016108d7565b600054610100900460ff1661312c5760405162461bcd60e51b81526004016108d790614519565b6126d8613478565b600054610100900460ff166126d85760405162461bcd60e51b81526004016108d790614519565b613163612692565b6033805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258612adb3390565b6000806131f984805190602001206040517f19457468657265756d205369676e6564204d6573736167653a0a3332000000006020820152603c8101829052600090605c01604051602081830303815290604052805190602001209050919050565b90506000806000613209866134ab565b60408051600081526020810180835289905260ff8316918101919091526060810184905260808101839052929550909350915060019060a0016020604051602081039080840390855afa158015613264573d6000803e3d6000fd5b5050604051601f19015198975050505050505050565b61141f8363a9059cbb60e01b84846040516024016128dd929190614209565b60006132ee826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661351f9092919063ffffffff16565b905080516000148061330f57508080602001905181019061330f9190614222565b61141f5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016108d7565b6001600160a01b0381163b6133db5760405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b60648201526084016108d7565b60008051602061457883398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b61341383613536565b6000825111806134205750805b1561141f57611efa8383613576565b60335460ff166126d85760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b60448201526064016108d7565b600054610100900460ff1661349f5760405162461bcd60e51b81526004016108d790614519565b6033805460ff19169055565b600080600083516041146135015760405162461bcd60e51b815260206004820152601d60248201527f5369673a20496e76616c6964207369676e6174757265206c656e67746800000060448201526064016108d7565b50505060208101516040820151606090920151909260009190911a90565b606061352e84846000856135a4565b949350505050565b61353f8161336e565b6040516001600160a01b038216907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a250565b606061359b83836040518060600160405280602781526020016145986027913961367f565b90505b92915050565b6060824710156136055760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b60648201526084016108d7565b600080866001600160a01b0316858760405161362191906144fd565b60006040518083038185875af1925050503d806000811461365e576040519150601f19603f3d011682016040523d82523d6000602084013e613663565b606091505b5091509150613674878383876136f7565b979650505050505050565b6060600080856001600160a01b03168560405161369c91906144fd565b600060405180830381855af49150503d80600081146136d7576040519150601f19603f3d011682016040523d82523d6000602084013e6136dc565b606091505b50915091506136ed868383876136f7565b9695505050505050565b6060831561376657825160000361375f576001600160a01b0385163b61375f5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016108d7565b508161352e565b61352e838381511561377b5781518083602001fd5b8060405162461bcd60e51b81526004016108d79190614564565b6001600160a01b03811681146116bf57600080fd5b6000602082840312156137bc57600080fd5b81356137c781613795565b9392505050565b80356137d981613795565b919050565b6000806000606084860312156137f357600080fd5b83356001600160401b0381111561380957600080fd5b8401610100818703121561381c57600080fd5b925060208401359150604084013561383381613795565b809150509250925092565b803567ffffffffffffffff19811681146137d957600080fd5b60006020828403121561386957600080fd5b61359b8261383e565b60006020828403121561388457600080fd5b81356001600160401b0381111561389a57600080fd5b820160a081850312156137c757600080fd5b6000602082840312156138be57600080fd5b81356001600160401b038111156138d457600080fd5b8201604081850312156137c757600080fd5b6000602082840312156138f857600080fd5b5035919050565b6000610160828403121561391257600080fd5b50919050565b60006020828403121561392a57600080fd5b81356001600160401b0381111561394057600080fd5b61352e848285016138ff565b6000806040838503121561395f57600080fd5b82356001600160401b038082111561397657600080fd5b613982868387016138ff565b9350602085013591508082111561399857600080fd5b508301606081860312156139ab57600080fd5b809150509250929050565b6000806000606084860312156139cb57600080fd5b83356139d681613795565b925060208401356139e681613795565b929592945050506040919091013590565b634e487b7160e01b600052604160045260246000fd5b60405161016081016001600160401b0381118282101715613a3057613a306139f7565b60405290565b604051601f8201601f191681016001600160401b0381118282101715613a5e57613a5e6139f7565b604052919050565b60006001600160401b03831115613a7f57613a7f6139f7565b613a92601f8401601f1916602001613a36565b9050828152838383011115613aa657600080fd5b828260208301376000602084830101529392505050565b600082601f830112613ace57600080fd5b61359b83833560208501613a66565b60008060408385031215613af057600080fd5b8235613afb81613795565b915060208301356001600160401b03811115613b1657600080fd5b613b2285828601613abd565b9150509250929050565b600060e08284031215613b3e57600080fd5b60405160e081018181106001600160401b0382111715613b6057613b606139f7565b6040528235613b6e81613795565b81526020830135613b7e81613795565b60208201526040830135613b9181613795565b60408201526060830135613ba481613795565b6060820152613bb5608084016137ce565b6080820152613bc660a084016137ce565b60a0820152613bd760c084016137ce565b60c08201529392505050565b60008060408385031215613bf657600080fd5b50508035926020909101359150565b600082601f830112613c1657600080fd5b813560206001600160401b03821115613c3157613c316139f7565b8160051b613c40828201613a36565b9283528481018201928281019087851115613c5a57600080fd5b83870192505b8483101561367457823582529183019190830190613c60565b600080600080600060a08688031215613c9157600080fd5b8535613c9c81613795565b94506020860135613cac81613795565b935060408601356001600160401b0380821115613cc857600080fd5b613cd489838a01613c05565b94506060880135915080821115613cea57600080fd5b613cf689838a01613c05565b93506080880135915080821115613d0c57600080fd5b50613d1988828901613abd565b9150509295509295909350565b803564ffffffffff811681146137d957600080fd5b60006101608284031215613d4e57600080fd5b613d56613a0d565b9050613d618261383e565b8152613d6f60208301613d26565b602082015260408201356040820152606082013560608201526080820135608082015260a082013560a082015260c082013560c082015260e082013560e0820152610100613dbe8184016137ce565b90820152610120828101356001600160401b0380821115613dde57600080fd5b613dea86838701613abd565b83850152610140925082850135915080821115613e0657600080fd5b50613e1385828601613abd565b82840152505092915050565b60008060408385031215613e3257600080fd5b82356001600160401b0380821115613e4957600080fd5b613e5586838701613d3b565b93506020850135915080821115613e6b57600080fd5b508301601f81018513613e7d57600080fd5b613b2285823560208401613a66565b60008083601f840112613e9e57600080fd5b5081356001600160401b03811115613eb557600080fd5b6020830191508360208260051b8501011115613ed057600080fd5b9250929050565b60008060008060408587031215613eed57600080fd5b84356001600160401b0380821115613f0457600080fd5b613f1088838901613e8c565b90965094506020870135915080821115613f2957600080fd5b50613f3687828801613e8c565b95989497509550505050565b600080600080600060a08688031215613f5a57600080fd5b8535613f6581613795565b94506020860135613f7581613795565b9350604086013592506060860135915060808601356001600160401b03811115613f9e57600080fd5b613d1988828901613abd565b634e487b7160e01b600052601160045260246000fd5b600082613fdd57634e487b7160e01b600052601260045260246000fd5b500490565b808202811582820484141761359e5761359e613faa565b8082018082111561359e5761359e613faa565b8181038181111561359e5761359e613faa565b6000808335601e1984360301811261403657600080fd5b8301803591506001600160401b0382111561405057600080fd5b602001915036819003821315613ed057600080fd5b60005b83811015614080578181015183820152602001614068565b50506000910152565b600081518084526140a1816020860160208601614065565b601f01601f19169290920160200192915050565b602081526000825160a060208401526140d160c0840182614089565b905060018060a01b0360208501511660408401526040840151606084015260608401516080840152608084015160a08401528091505092915050565b60006020828403121561411f57600080fd5b5051919050565b60208082526021908201527f53616c65734d616e616765723a207377617020616d6f756e7420746f6f206c6f6040820152607760f81b606082015260800190565b600060a0823603121561417957600080fd5b60405160a081016001600160401b03828210818311171561419c5761419c6139f7565b816040526141a98561383e565b83526141b760208601613d26565b6020840152604085013591506141cc82613795565b8160408401526060850135606084015260808501359150808211156141f057600080fd5b506141fd36828601613abd565b60808301525092915050565b6001600160a01b03929092168252602082015260400190565b60006020828403121561423457600080fd5b815180151581146137c757600080fd5b6000808335601e1984360301811261425b57600080fd5b8301803591506001600160401b0382111561427557600080fd5b602001915061012081023603821315613ed057600080fd5b634e487b7160e01b600052603260045260246000fd5b600081518084526020808501945080840160005b838110156142d3578151875295820195908201906001016142b7565b509495945050505050565b6001600160a01b0384168152608060208201819052600090614302908301856142a3565b828103604084015261431481856142a3565b8381036060909401939093525050600081526020019392505050565b60408152600061434360408301856142a3565b828103602084015261435581856142a3565b95945050505050565b600061359e3683613d3b565b60018060a01b038616815284602082015283604082015260806060820152816080820152818360a0830137600081830160a090810191909152601f909201601f19160101949350505050565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b19195b1959d85d1958d85b1b60a21b606082015260800190565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b6163746976652070726f787960a01b606082015260800190565b6001600160a01b038316815260406020820181905260009061352e90830184614089565b60006101406001600160401b03198d16835264ffffffffff8c16602084015260018060a01b03808c1660408501528a60608501528960808501528860a08501528760c08501528160e08501526144ca82850188614089565b92508561010085015280851661012085015250509b9a5050505050505050505050565b8183823760009101908152919050565b6000825161450f818460208701614065565b9190910192915050565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b60208152600061359b602083018461408956fe360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564396cc212fb89072d8d9db8917ca50a364cf7dabc0b5420a8e675bd1b9082bed3a26469706673582212207d2c2813e57b312af083884247fc2146f764006199be563da58c9b9fb22939c364736f6c63430008110033

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

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

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