Goerli Testnet

Contract

0x1d0eC820526E101F4253978217949A755380f501
Source Code
Transaction Hash
Method
Block
From
To
Value
Wrap Batch99175362023-10-23 14:01:1243 days 14 hrs ago1698069672IN
0x1d0eC8...5380f501
0 ETH0.000473651.43880566
Wrap Batch98881402023-10-18 12:02:4848 days 16 hrs ago1697630568IN
0x1d0eC8...5380f501
0 ETH0.001140031.50000001
Wrap Batch98858632023-10-18 2:45:3649 days 1 hr ago1697597136IN
0x1d0eC8...5380f501
0 ETH0.000784192
Wrap Batch98857762023-10-18 2:23:4849 days 2 hrs ago1697595828IN
0x1d0eC8...5380f501
0 ETH0.000778612
Wrap Batch98131892023-10-05 11:22:2461 days 17 hrs ago1696504944IN
0x1d0eC8...5380f501
0 ETH0.000695542
Wrap Batch98131782023-10-05 11:19:2461 days 17 hrs ago1696504764IN
0x1d0eC8...5380f501
0 ETH0.001264482
Wrap Batch98114352023-10-05 3:57:2462 days 46 mins ago1696478244IN
0x1d0eC8...5380f501
0 ETH0.000578952
Wrap Batch97609912023-09-26 5:54:4870 days 22 hrs ago1695707688IN
0x1d0eC8...5380f501
0 ETH0.000872772.50000001
Wrap Batch89684692023-05-09 7:31:12210 days 21 hrs ago1683617472IN
0x1d0eC8...5380f501
0 ETH0.03759555169.64280363
Wrap Batch89684672023-05-09 7:30:48210 days 21 hrs ago1683617448IN
0x1d0eC8...5380f501
0 ETH0.03728924164.69352517
Wrap Batch89684652023-05-09 7:30:24210 days 21 hrs ago1683617424IN
0x1d0eC8...5380f501
0 ETH0.03895876172.06721241
Wrap Batch89684622023-05-09 7:29:48210 days 21 hrs ago1683617388IN
0x1d0eC8...5380f501
0 ETH0.03732052164.83167189
Wrap Batch89684602023-05-09 7:29:24210 days 21 hrs ago1683617364IN
0x1d0eC8...5380f501
0 ETH0.0385619170.31441578
Wrap Batch89684572023-05-09 7:28:48210 days 21 hrs ago1683617328IN
0x1d0eC8...5380f501
0 ETH0.03728744164.68555845
Wrap Batch89684562023-05-09 7:28:24210 days 21 hrs ago1683617304IN
0x1d0eC8...5380f501
0 ETH0.03791787167.46995197
Wrap Batch89684522023-05-09 7:27:36210 days 21 hrs ago1683617256IN
0x1d0eC8...5380f501
0 ETH0.03470264153.26940477
Wrap Batch89684492023-05-09 7:27:00210 days 21 hrs ago1683617220IN
0x1d0eC8...5380f501
0 ETH0.03636669160.61890937
Edit Tariff89683502023-05-09 7:03:12210 days 21 hrs ago1683615792IN
0x1d0eC8...5380f501
0 ETH0.0095282200
Edit Tariff89679892023-05-09 5:37:48210 days 23 hrs ago1683610668IN
0x1d0eC8...5380f501
0 ETH0.0190564400
Wrap Batch89444942023-05-05 4:57:48214 days 23 hrs ago1683262668IN
0x1d0eC8...5380f501
0 ETH0.02992766132.18000164
Wrap Batch89438572023-05-05 2:23:00215 days 2 hrs ago1683253380IN
0x1d0eC8...5380f501
0 ETH0.0225931899.78616532
Set Trusted Wrap...89384082023-05-04 3:55:48216 days 47 mins ago1683172548IN
0x1d0eC8...5380f501
0 ETH0.0031858761.7119148
Auth Agent89383302023-05-04 3:37:24216 days 1 hr ago1683171444IN
0x1d0eC8...5380f501
0 ETH0.0523834200
Auth Agent89383182023-05-04 3:35:00216 days 1 hr ago1683171300IN
0x1d0eC8...5380f501
0 ETH0.0421026200
New Tariff89383042023-05-04 3:31:48216 days 1 hr ago1683171108IN
0x1d0eC8...5380f501
0 ETH0.0629174200
View all transactions

Latest 25 internal transactions (View All)

Advanced mode:
Parent Txn Hash Block From To Value
99175362023-10-23 14:01:1243 days 14 hrs ago1698069672
0x1d0eC8...5380f501
0 ETH
99175362023-10-23 14:01:1243 days 14 hrs ago1698069672
0x1d0eC8...5380f501
0 ETH
99175362023-10-23 14:01:1243 days 14 hrs ago1698069672
0x1d0eC8...5380f501
0 ETH
99172072023-10-23 12:39:1243 days 16 hrs ago1698064752
0x1d0eC8...5380f501
0 ETH
98881402023-10-18 12:02:4848 days 16 hrs ago1697630568
0x1d0eC8...5380f501
0 ETH
98881402023-10-18 12:02:4848 days 16 hrs ago1697630568
0x1d0eC8...5380f501
0 ETH
98881402023-10-18 12:02:4848 days 16 hrs ago1697630568
0x1d0eC8...5380f501
0 ETH
98881402023-10-18 12:02:4848 days 16 hrs ago1697630568
0x1d0eC8...5380f501
0 ETH
98881402023-10-18 12:02:4848 days 16 hrs ago1697630568
0x1d0eC8...5380f501
0 ETH
98880702023-10-18 11:47:2448 days 16 hrs ago1697629644
0x1d0eC8...5380f501
0 ETH
98858632023-10-18 2:45:3649 days 1 hr ago1697597136
0x1d0eC8...5380f501
0 ETH
98858632023-10-18 2:45:3649 days 1 hr ago1697597136
0x1d0eC8...5380f501
0 ETH
98858632023-10-18 2:45:3649 days 1 hr ago1697597136
0x1d0eC8...5380f501
0 ETH
98858372023-10-18 2:38:2449 days 2 hrs ago1697596704
0x1d0eC8...5380f501
0 ETH
98857762023-10-18 2:23:4849 days 2 hrs ago1697595828
0x1d0eC8...5380f501
0 ETH
98857762023-10-18 2:23:4849 days 2 hrs ago1697595828
0x1d0eC8...5380f501
0 ETH
98857762023-10-18 2:23:4849 days 2 hrs ago1697595828
0x1d0eC8...5380f501
0 ETH
98857562023-10-18 2:18:3649 days 2 hrs ago1697595516
0x1d0eC8...5380f501
0 ETH
98857422023-10-18 2:14:4849 days 2 hrs ago1697595288
0x1d0eC8...5380f501
0 ETH
98832082023-10-17 15:59:3649 days 12 hrs ago1697558376
0x1d0eC8...5380f501
0 ETH
98131892023-10-05 11:22:2461 days 17 hrs ago1696504944
0x1d0eC8...5380f501
0 ETH
98131892023-10-05 11:22:2461 days 17 hrs ago1696504944
0x1d0eC8...5380f501
0 ETH
98131892023-10-05 11:22:2461 days 17 hrs ago1696504944
0x1d0eC8...5380f501
0 ETH
98131782023-10-05 11:19:2461 days 17 hrs ago1696504764
0x1d0eC8...5380f501
0 ETH
98131782023-10-05 11:19:2461 days 17 hrs ago1696504764
0x1d0eC8...5380f501
0 ETH
View All Internal Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
BatchWorkerV2

Compiler Version
v0.8.16+commit.07a7930e

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion, MIT license

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 18 : BatchWorkerV2.sol
// SPDX-License-Identifier: MIT
// ENVELOP(NIFTSY) protocol V1 for NFT. Batch Worker 

import "SafeERC20.sol";
import "Ownable.sol";
import "ITrustedWrapperV2.sol";
import "IERC20Extended.sol";
import "ServiceProvider.sol";



pragma solidity 0.8.16;

contract BatchWorkerV2 is Ownable, ServiceProvider {
    using SafeERC20 for IERC20Extended;

    ITrustedWrapperV2 public trustedWrapper;
    
    constructor (address _subscrRegistry) 
        ServiceProvider(_subscrRegistry)
    {}

    function wrapBatch(
        ETypes.INData[] calldata _inDataS, 
        ETypes.AssetItem[] calldata _collateralERC20,
        address[] memory _receivers
    ) public payable {
        _checkAndFixSubscription(msg.sender);
        require(
            _inDataS.length == _receivers.length, 
            "Array params must have equal length"
        );
        // make wNFTs
        for (uint256 i = 0; i < _inDataS.length; i++) {
            // wrap
            trustedWrapper.wrapUnsafe{value: (msg.value / _receivers.length)}(
                _inDataS[i],
                _collateralERC20,
                _receivers[i]
            );
            
            // Transfer original NFTs  to wrapper
            if (_inDataS[i].inAsset.asset.assetType == ETypes.AssetType.ERC721 ||
                _inDataS[i].inAsset.asset.assetType == ETypes.AssetType.ERC1155 ) 
            {
                trustedWrapper.transferIn(
                    _inDataS[i].inAsset, 
                    msg.sender
                );
            }
        }

        ETypes.AssetItem memory totalERC20Collateral;
        uint256 totalNativeAmount;
        for (uint256 i = 0; i < _collateralERC20.length; i ++) {

            if (_collateralERC20[i].asset.assetType == ETypes.AssetType.ERC20) {
            
                totalERC20Collateral.asset.assetType = _collateralERC20[i].asset.assetType;
                totalERC20Collateral.asset.contractAddress = _collateralERC20[i].asset.contractAddress; 
                totalERC20Collateral.tokenId = _collateralERC20[i].tokenId;
                // We need construct totalERC20Collateral due make one transfer
                // instead of maked wNFT counts
                totalERC20Collateral.amount = _collateralERC20[i].amount * _receivers.length;
                
                uint256 amountTransfered = trustedWrapper.transferIn(
                   totalERC20Collateral, 
                    msg.sender
                );
                require(amountTransfered == totalERC20Collateral.amount, "Check transfer ERC20 amount fail");
                
            }

            if (_collateralERC20[i].asset.assetType == ETypes.AssetType.NATIVE) {
                    totalNativeAmount += _collateralERC20[i].amount * _receivers.length;    
                } 
        }

        require(totalNativeAmount == msg.value,  "Native amount check failed");
    }


    function addCollateralBatch(
        address[] calldata _wNFTAddress, 
        uint256[] calldata _wNFTTokenId, 
        ETypes.AssetItem[] calldata _collateralERC20
    ) public payable {
        _checkAndFixSubscription(msg.sender);
        require(_wNFTAddress.length == _wNFTTokenId.length, "Array params must have equal length");
        
        for (uint256 i = 0; i < _collateralERC20.length; i ++) {
            if (_collateralERC20[i].asset.assetType == ETypes.AssetType.ERC20) {
                // 1. Transfer all erc20 tokens to BatchWorker        
                IERC20Extended(_collateralERC20[i].asset.contractAddress).safeTransferFrom(
                    msg.sender,
                    address(this),
                    _collateralERC20[i].amount * _wNFTAddress.length
                );
                // 2. approve for spending to wrapper
                IERC20Extended(_collateralERC20[i].asset.contractAddress).safeIncreaseAllowance(
                    address(trustedWrapper),
                    _collateralERC20[i].amount * _wNFTAddress.length
                );
            }
        }

            
        uint256 valuePerWNFT = msg.value / _wNFTAddress.length;
        for (uint256 i = 0; i < _wNFTAddress.length; i ++){
            trustedWrapper.addCollateral{value: valuePerWNFT}(
                _wNFTAddress[i],
                _wNFTTokenId[i],
                _collateralERC20
            );
        }

        if (valuePerWNFT * _wNFTAddress.length < msg.value ){
            address payable s = payable(msg.sender);
            s.transfer(msg.value - valuePerWNFT * _wNFTAddress.length);
        }
    }

    ////////////////////////////////////////
    //     Admin functions               ///
    ////////////////////////////////////////
    function setTrustedWrapper(address _wrapper) public onlyOwner {
        trustedWrapper = ITrustedWrapperV2(_wrapper);
        require(trustedWrapper.trustedOperator(address(this)), "Only for exact wrapper");
    }

    function newTariff(Tariff memory _newTariff) external onlyOwner returns(uint256 tariffIndex) {
        tariffIndex = _registerServiceTariff(_newTariff); 
    }

    function editTariff(
        uint256 _tariffIndex, 
        uint256 _timelockPeriod,
        uint256 _ticketValidPeriod,
        uint256 _counter,
        bool _isAvailable,
        address _beneficiary
    ) external onlyOwner 
    {
        _editServiceTariff(
            _tariffIndex, 
            _timelockPeriod,
            _ticketValidPeriod,
            _counter,
            _isAvailable,
            _beneficiary
        );
    }

    function addPayOption(
        uint256 _tariffIndex,
        address _paymentToken,
        uint256 _paymentAmount,
        uint16 _agentFeePercent
    ) external onlyOwner returns(uint256 index)
    {
        index = _addTariffPayOption(
            _tariffIndex,
            _paymentToken,
            _paymentAmount,
            _agentFeePercent
        );
    }

    function editPayOption(
        uint256 _tariffIndex,
        uint256 _payWithIndex, 
        address _paymentToken,
        uint256 _paymentAmount,
        uint16 _agentFeePercent
    ) external onlyOwner
    {
        _editTariffPayOption(
            _tariffIndex,
            _payWithIndex, 
            _paymentToken,
            _paymentAmount,
            _agentFeePercent
        );

    }

    function authAgent(
        address _agent,
        uint256[] memory _serviceTariffIndexes
    ) external onlyOwner returns (uint256[] memory actualTariffs)
    {
        actualTariffs = _authorizeAgentForService(
            _agent,
            _serviceTariffIndexes
        );

    }

    function setSubscriptionRegestry(address _subscrRegistry) external onlyOwner {
        subscriptionRegistry = ISubscriptionRegistry(_subscrRegistry);
    }
    
    /////////////////////////////////////////////////////////////////////

    function checkUser(address _user) external view returns (bool ok, bool needFix) {
        return _checkUserSubscription(_user); 

    }





    
}

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

pragma solidity ^0.8.0;

import "IERC20.sol";
import "draft-IERC20Permit.sol";
import "Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using Address for address;

    function safeTransfer(
        IERC20 token,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    function safeTransferFrom(
        IERC20 token,
        address from,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    function safeIncreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        uint256 newAllowance = token.allowance(address(this), spender) + value;
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    function safeDecreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            uint256 newAllowance = oldAllowance - value;
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
        }
    }

    function safePermit(
        IERC20Permit 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(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        if (returndata.length > 0) {
            // Return data is optional
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}

File 3 of 18 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.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 4 of 18 : draft-IERC20Permit.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-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 IERC20Permit {
    /**
     * @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 5 of 18 : Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     *
     * [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://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

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

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return 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 6 of 18 : Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

import "Context.sol";

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

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

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _transferOwnership(_msgSender());
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

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

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
    }

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

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

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

File 7 of 18 : Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

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

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

File 8 of 18 : ITrustedWrapperV2.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.16;

import "IWrapper.sol";

interface ITrustedWrapperV2 is IWrapper  {

    function trustedOperator(address _operator) external view returns(bool);    
    
    function wrapUnsafe(
        ETypes.INData calldata _inData, 
        ETypes.AssetItem[] calldata _collateral, 
        address _wrappFor
    ) 
        external
        payable
        returns (ETypes.AssetItem memory); 

    function transferIn(
        ETypes.AssetItem memory _assetItem,
        address _from
    ) 
        external
        payable  
    returns (uint256 _transferedValue);
   
}

File 9 of 18 : IWrapper.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.16;

//import "IERC721Enumerable.sol";
import "LibEnvelopTypes.sol";

interface IWrapper  {

    event WrappedV1(
        address indexed inAssetAddress,
        address indexed outAssetAddress, 
        uint256 indexed inAssetTokenId, 
        uint256 outTokenId,
        address wnftFirstOwner,
        uint256 nativeCollateralAmount,
        bytes2  rules
    );

    event UnWrappedV1(
        address indexed wrappedAddress,
        address indexed originalAddress,
        uint256 indexed wrappedId, 
        uint256 originalTokenId, 
        address beneficiary, 
        uint256 nativeCollateralAmount,
        bytes2  rules 
    );

    event CollateralAdded(
        address indexed wrappedAddress,
        uint256 indexed wrappedId,
        uint8   assetType,
        address collateralAddress,
        uint256 collateralTokenId,
        uint256 collateralBalance
    );

    event PartialUnWrapp(
        address indexed wrappedAddress,
        uint256 indexed wrappedId,
        uint256 lastCollateralIndex
    );
    event SuspiciousFail(
        address indexed wrappedAddress,
        uint256 indexed wrappedId, 
        address indexed failedContractAddress
    );

    event EnvelopFee(
        address indexed receiver,
        address indexed wNFTConatract,
        uint256 indexed wNFTTokenId,
        uint256 amount
    );

    function wrap(
        ETypes.INData calldata _inData, 
        ETypes.AssetItem[] calldata _collateral, 
        address _wrappFor
    ) 
        external 
        payable 
    returns (ETypes.AssetItem memory);

    // function wrapUnsafe(
    //     ETypes.INData calldata _inData, 
    //     ETypes.AssetItem[] calldata _collateral, 
    //     address _wrappFor
    // ) 
    //     external 
    //     payable
    // returns (ETypes.AssetItem memory);

    function addCollateral(
        address _wNFTAddress, 
        uint256 _wNFTTokenId, 
        ETypes.AssetItem[] calldata _collateral
    ) external payable;

    // function addCollateralUnsafe(
    //     address _wNFTAddress, 
    //     uint256 _wNFTTokenId, 
    //     ETypes.AssetItem[] calldata _collateral
    // ) 
    //     external 
    //     payable;

    function unWrap(
        address _wNFTAddress, 
        uint256 _wNFTTokenId
    ) external; 

    function unWrap(
        ETypes.AssetType _wNFTType, 
        address _wNFTAddress, 
        uint256 _wNFTTokenId
    ) external; 

    function unWrap(
        ETypes.AssetType _wNFTType, 
        address _wNFTAddress, 
        uint256 _wNFTTokenId, 
        bool _isEmergency
    ) external;

    function chargeFees(
        address _wNFTAddress, 
        uint256 _wNFTTokenId, 
        address _from, 
        address _to,
        bytes1 _feeType
    ) 
        external  
        returns (bool);   

    ////////////////////////////////////////////////////////////////////// 
    
    function MAX_COLLATERAL_SLOTS() external view returns (uint256);
    function protocolTechToken() external view returns (address);
    function protocolWhiteList() external view returns (address);
    //function trustedOperators(address _operator) external view returns (bool); 
    //function lastWNFTId(ETypes.AssetType _assetType) external view returns (ETypes.NFTItem); 

    function getWrappedToken(address _wNFTAddress, uint256 _wNFTTokenId) 
        external 
        view 
        returns (ETypes.WNFT memory);

    function getOriginalURI(address _wNFTAddress, uint256 _wNFTTokenId) 
        external 
        view 
        returns(string memory); 
    
    function getCollateralBalanceAndIndex(
        address _wNFTAddress, 
        uint256 _wNFTTokenId,
        ETypes.AssetType _collateralType, 
        address _erc,
        uint256 _tokenId
    ) external view returns (uint256, uint256);
   
}

File 10 of 18 : IERC721Enumerable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC721/extensions/IERC721Enumerable.sol)

pragma solidity ^0.8.0;

import "IERC721.sol";

/**
 * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
 * @dev See https://eips.ethereum.org/EIPS/eip-721
 */
interface IERC721Enumerable is IERC721 {
    /**
     * @dev Returns the total amount of tokens stored by the contract.
     */
    function totalSupply() external view returns (uint256);

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

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

File 11 of 18 : IERC721.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC721/IERC721.sol)

pragma solidity ^0.8.0;

import "IERC165.sol";

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

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

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

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

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

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

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

    /**
     * @dev Transfers `tokenId` token from `from` to `to`.
     *
     * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
     * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
     * understand this adds an external call which potentially creates a reentrancy vulnerability.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address from,
        address to,
        uint256 tokenId
    ) external;

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

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

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

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

File 12 of 18 : 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 13 of 18 : LibEnvelopTypes.sol
// SPDX-License-Identifier: MIT
// ENVELOP(NIFTSY) protocol V1 for NFT. 
pragma solidity 0.8.16;

library ETypes {

    enum AssetType {EMPTY, NATIVE, ERC20, ERC721, ERC1155, FUTURE1, FUTURE2, FUTURE3}
    
    struct Asset {
        AssetType assetType;
        address contractAddress;
    }

    struct AssetItem {
        Asset asset;
        uint256 tokenId;
        uint256 amount;
    }

    struct NFTItem {
        address contractAddress;
        uint256 tokenId;   
    }

    struct Fee {
        bytes1 feeType;
        uint256 param;
        address token; 
    }

    struct Lock {
        bytes1 lockType;
        uint256 param; 
    }

    struct Royalty {
        address beneficiary;
        uint16 percent;
    }

    struct WNFT {
        AssetItem inAsset;
        AssetItem[] collateral;
        address unWrapDestination;
        Fee[] fees;
        Lock[] locks;
        Royalty[] royalties;
        bytes2 rules;

    }

    struct INData {
        AssetItem inAsset;
        address unWrapDestination;
        Fee[] fees;
        Lock[] locks;
        Royalty[] royalties;
        AssetType outType;
        uint256 outBalance;      //0- for 721 and any amount for 1155
        bytes2 rules;

    }

    struct WhiteListItem {
        bool enabledForFee;
        bool enabledForCollateral;
        bool enabledRemoveFromCollateral;
        address transferFeeModel;
    }

    struct Rules {
        bytes2 onlythis;
        bytes2 disabled;
    }

}

File 14 of 18 : IERC20Extended.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.16;

import "IERC20.sol";

interface IERC20Extended is  IERC20 {
     function mint(address _to, uint256 _value) external;
}

File 15 of 18 : ServiceProvider.sol
// SPDX-License-Identifier: MIT
// ENVELOP(NIFTSY) Subscription Registry Contract V2


/// The subscription platform operates with the following role model 
/// (it is assumed that the actor with the role is implemented as a contract).
/// `Service Provider` is a contract whose services are sold by subscription.
/// `Agent` - a contract that sells a subscription on behalf ofservice provider. 
///  May receive sales commission
///  `Platform` - SubscriptionRegistry contract that performs processingsubscriptions, 
///  fares, tickets


pragma solidity 0.8.16;

import "ISubscriptionRegistry.sol";

/// @title ServiceProvider abstract contract 
/// @author Envelop project Team
/// @notice Abstract contract implements subscribing features.
/// For use with SubscriptionRegestry
/// @dev Use this code in service provider contract that
/// want use subscription. One contract = one servie
/// Please see example folder
abstract contract ServiceProvider {

	address public serviceProvider;
    ISubscriptionRegistry public subscriptionRegistry;

	constructor(address _subscrRegistry) {
        require(_subscrRegistry != address(0), 'Non zero only');
	 	serviceProvider = address(this);
        subscriptionRegistry = ISubscriptionRegistry(_subscrRegistry);
	}

    function _registerServiceTariff(Tariff memory _newTariff) 
        internal virtual returns(uint256)
    {
        return subscriptionRegistry.registerServiceTariff(_newTariff);
    }

    
    function _editServiceTariff(
        uint256 _tariffIndex, 
        uint256 _timelockPeriod,
        uint256 _ticketValidPeriod,
        uint256 _counter,
        bool _isAvailable,
        address _beneficiary
    ) internal virtual 
    {
        subscriptionRegistry.editServiceTariff(
            _tariffIndex, 
            _timelockPeriod,
            _ticketValidPeriod,
            _counter,
            _isAvailable,
            _beneficiary
        );
    }

    function _addTariffPayOption(
        uint256 _tariffIndex,
        address _paymentToken,
        uint256 _paymentAmount,
        uint16 _agentFeePercent
    ) internal virtual returns(uint256)
    {
        return subscriptionRegistry.addTariffPayOption(
            _tariffIndex,
            _paymentToken,
            _paymentAmount,
            _agentFeePercent
        );
    }
    
    function _editTariffPayOption(
        uint256 _tariffIndex,
        uint256 _payWithIndex, 
        address _paymentToken,
        uint256 _paymentAmount,
        uint16 _agentFeePercent
    ) internal virtual 
    {
        subscriptionRegistry.editTariffPayOption(
            _tariffIndex,
            _payWithIndex, 
            _paymentToken,
            _paymentAmount,
            _agentFeePercent
        );
    } 

    function _authorizeAgentForService(
        address _agent,
        uint256[] memory _serviceTariffIndexes
    ) internal virtual returns (uint256[] memory)
    {
        // TODO Check agent
        return subscriptionRegistry.authorizeAgentForService(
            _agent,
            _serviceTariffIndexes
        );
    }

    ////////////////////////////
    //        Main USAGE      //
    ////////////////////////////
    function _checkAndFixSubscription(address _user) 
        internal 
        returns (bool ok) 
    {
            ok = subscriptionRegistry.checkAndFixUserSubscription(
                _user
            );
    }

    function _checkUserSubscription(address _user) 
        internal 
        view 
        returns (bool ok, bool needFix)
    {
            (ok, needFix) = subscriptionRegistry.checkUserSubscription(
                _user,
                address(this)  
            );
    }
}

File 16 of 18 : ISubscriptionRegistry.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.16;

import {SubscriptionType, PayOption, Tariff, Ticket} from "SubscriptionRegistry.sol";
interface ISubscriptionRegistry   {

    /**
     * @notice Add new tariff for caller
     * @dev Call this method from ServiceProvider
     * for setup new tariff 
     * using `Tariff` data type(please see above)
     *
     * @param _newTariff full encded Tariff object
     * @return last added tariff index in  Tariff[] array 
     * for current Service Provider (msg.sender)
     */
    function registerServiceTariff(Tariff calldata _newTariff) external returns(uint256);
    
    
    /**
     * @notice Authorize agent for caller service provider
     * @dev Call this method from ServiceProvider
     *
     * @param _agent  - address of contract that implement Agent role 
     * @param _serviceTariffIndexes  - array of index in `availableTariffs` array
     * that available for given `_agent` 
     * @return full array of actual tarifs for this agent 
     */
    function authorizeAgentForService(
        address _agent,
        uint256[] calldata _serviceTariffIndexes
    ) external returns (uint256[] memory);

    /**
     * @notice By Ticket for subscription
     * @dev Call this method from Agent
     *
     * @param _service  - Service Provider address 
     * @param _tariffIndex  - index in  `availableTariffs` array 
     * @param _payWithIndex  - index in `tariff.payWith` array 
     * @param _buyFor - address for whome this ticket would be bought 
     * @param _payer - address of payer for this ticket
     * @return ticket structure that would be use for validate service process
     */ 
    function buySubscription(
        address _service,
        uint256 _tariffIndex,
        uint256 _payWithIndex,
        address _buyFor,
        address _payer
    ) external payable returns(Ticket memory ticket);

    /**
     * @notice Edit tariff for caller
     * @dev Call this method from ServiceProvider
     * for setup new tariff 
     * using `Tariff` data type(please see above)
     *
     * @param _tariffIndex  - index in `availableTariffs` array 
     * @param _timelockPeriod - see SubscriptionType notice above
     * @param _ticketValidPeriod - see SubscriptionType notice above
     * @param _counter - see SubscriptionType notice above
     * @param _isAvailable - see SubscriptionType notice above
     * @param _beneficiary - see SubscriptionType notice above
     */
    function editServiceTariff(
        uint256 _tariffIndex, 
        uint256 _timelockPeriod,
        uint256 _ticketValidPeriod,
        uint256 _counter,
        bool _isAvailable,
        address _beneficiary
    ) external;

    /**
     * @notice Add tariff PayOption for exact service
     * @dev Call this method from ServiceProvider
     * for add tariff PayOption 
     *
     * @param _tariffIndex  - index in `availableTariffs` array 
     * @param _paymentToken - see PayOption notice above
     * @param _paymentAmount - see PayOption notice above
     * @param _agentFeePercent - see PayOption notice above
     * @return last added PaymentOption index in array 
     * for _tariffIndex Tariff of caller Service Provider (msg.sender)
     */
    function addTariffPayOption(
        uint256 _tariffIndex,
        address _paymentToken,
        uint256 _paymentAmount,
        uint16 _agentFeePercent
    ) external returns(uint256);
    
    /**
     * @notice Edit tariff PayOption for exact service
     * @dev Call this method from ServiceProvider
     * for edit tariff PayOption 
     *
     * @param _tariffIndex  - index in  `availableTariffs` array 
     * @param _payWithIndex  - index in `tariff.payWith` array 
     * @param _paymentToken - see PayOption notice above
     * @param _paymentAmount - see PayOption notice above
     * @param _agentFeePercent - see PayOption notice above
     * for _tariffIndex Tariff of caller Service Provider (msg.sender)
     */
    function editTariffPayOption(
        uint256 _tariffIndex,
        uint256 _payWithIndex, 
        address _paymentToken,
        uint256 _paymentAmount,
        uint16 _agentFeePercent
    ) external; 
    
    /**
     * @notice Check that `_user` have still valid ticket for this service.
     * @dev Call this method from any context
     *
     * @param _user  - address of user who has an ticket and who trying get service 
     * @param _service - address of Service Provider
     * @return ok True in case ticket is valid
     * @return needFix True in case ticket has counter > 0
     */
    function checkUserSubscription(
        address _user, 
        address _service
    ) external view returns (bool ok, bool needFix);


    /**
     * @notice Check that `_user` have still valid ticket for this service.
     * Decrement ticket counter in case it > 0
     * @dev Call this method from ServiceProvider
     *
     * @param _user  - address of user who has an ticket and who trying get service 
     * @return ok True in case ticket is valid
     */
    function checkAndFixUserSubscription(address _user) external returns (bool ok);

    /**
     * @notice Decrement ticket counter in case it > 0
     * @dev Call this method from new SubscriptionRegistry in case of upgrade
     *
     * @param _user  - address of user who has an ticket and who trying get service 
     * @param _serviceFromProxy  - address of service from more new SubscriptionRegistry contract 
     */
    function fixUserSubscription(address _user, address _serviceFromProxy) external;


    /**
     * @notice Returns `_user` ticket for this service.
     * @dev Call this method from any context
     *
     * @param _user  - address of user who has an ticket and who trying get service 
     * @param _service - address of Service Provider
     * @return ticket
     */
    function getUserTicketForService(
        address _service,
        address _user
    ) external view returns(Ticket memory); 
    
    /**
     * @notice Returns array of Tariff for `_service`
     * @dev Call this method from any context
     *
     * @param _service - address of Service Provider
     * @return Tariff array
     */
    function getTariffsForService(address _service) external view returns (Tariff[] memory);

    /**
     * @notice Returns ticket price include any fees
     * @dev Call this method from any context
     *
     * @param _service - address of Service Provider
     * @param _tariffIndex  - index in  `availableTariffs` array 
     * @param _payWithIndex  - index in `tariff.payWith` array 
     * @return tulpe with payment token an ticket price 
     */
    function getTicketPrice(
        address _service,
        uint256 _tariffIndex,
        uint256 _payWithIndex
    ) external view returns (address, uint256);

    /**
     * @notice Returns array of Tariff for `_service` assigned to `_agent`
     * @dev Call this method from any context
     *
     * @param _agent - address of Agent
     * @param _service - address of Service Provider
     * @return Tariff array
     */
    function getAvailableAgentsTariffForService(
        address _agent, 
        address _service
    ) external view returns(Tariff[] memory); 
}

File 17 of 18 : SubscriptionRegistry.sol
// SPDX-License-Identifier: MIT
// ENVELOP(NIFTSY) Team. Subscription Registry Contract V2
pragma solidity 0.8.16;

import "Ownable.sol";
import "SafeERC20.sol";
import "ITrustedWrapper.sol";
import "LibEnvelopTypes.sol";
import "ISubscriptionRegistry.sol";

/// The subscription platform operates with the following role model 
/// (it is assumed that the actor with the role is implemented as a contract).
/// `Service Provider` is a contract whose services are sold by subscription.
/// `Agent` - a contract that sells a subscription on behalf ofservice provider. 
///  May receive sales commission
///  `Platform` - SubscriptionRegistry contract that performs processingsubscriptions, 
///  fares, tickets

    struct SubscriptionType {
        uint256 timelockPeriod;    // in seconds e.g. 3600*24*30*12 = 31104000 = 1 year
        uint256 ticketValidPeriod; // in seconds e.g. 3600*24*30    =  2592000 = 1 month
        uint256 counter;     // For case when ticket valid for N usage, e.g. for Min N NFTs          
        bool isAvailable;    // USe for stop using tariff because we can`t remove tariff from array 
        address beneficiary; // Who will receive payment for tickets
    }
    struct PayOption {
        address paymentToken;   // token contract address or zero address for native token(ETC etc)
        uint256 paymentAmount;  // ticket price exclude any fees
        uint16 agentFeePercent; // 100%-10000, 20%-2000, 3%-300 
    }

    struct Tariff {
        SubscriptionType subscription; // link to subscriptionType
        PayOption[] payWith; // payment option array. Use it for price in defferent tokens
    }

    // native subscribtionManager tickets format
    struct Ticket {
        uint256 validUntil; // Unixdate, tickets not valid after
        uint256 countsLeft; // for tarif with fixed use counter
    }

/// @title Base contract in Envelop Subscription Platform 
/// @author Envelop Team
/// @notice You can use this contract for make and operate any on-chain subscriptions
/// @dev  Contract that performs processing subscriptions, fares(tariffs), tickets
/// @custom:please see example folder.
contract SubscriptionRegistry is Ownable {
    using SafeERC20 for IERC20;

    uint256 constant public PERCENT_DENOMINATOR = 10000;

    /// @notice Envelop Multisig contract
    address public platformOwner; 
    
    /// @notice Platform owner can receive fee from each payments
    uint16 public platformFeePercent = 50; // 100%-10000, 20%-2000, 3%-300


    /// @notice address used for wrapp & lock incoming assets
    address  public mainWrapper; 
    /// @notice Used in case upgrade this contract
    address  public previousRegistry; 
    /// @notice Used in case upgrade this contract
    address  public proxyRegistry; 

    /// @notice Only white listed assets can be used on platform
    mapping(address => bool) public whiteListedForPayments;
    
    /// @notice from service(=smart contract address) to tarifs
    mapping(address => Tariff[]) public availableTariffs;

    /// @notice from service to agent to available tarifs(tarif index);
    mapping(address => mapping(address => uint256[])) public agentServiceRegistry;
     
    
    /// @notice mapping from user addres to service contract address  to ticket
    mapping(address => mapping(address => Ticket)) public userTickets;

    event PlatfromFeeChanged(uint16 indexed newPercent);
    event WhitelistPaymentTokenChanged(address indexed asset, bool indexed state);
    event TariffChanged(address indexed service, uint256 indexed tariffIndex);
    event TicketIssued(
        address indexed service, 
        address indexed agent, 
        address indexed forUser, 
        uint256 tariffIndex
    );

    constructor(address _platformOwner) {
        require(_platformOwner != address(0),'Zero platform fee receiver');
        platformOwner = _platformOwner;
    } 
   
    /**
     * @notice Add new tariff for caller
     * @dev Call this method from ServiceProvider
     * for setup new tariff 
     * using `Tariff` data type(please see above)
     *
     * @param _newTariff full encded Tariff object
     * @return last added tariff index in  Tariff[] array 
     * for current Service Provider (msg.sender)
     */
    function registerServiceTariff(Tariff calldata _newTariff) 
        external 
        returns(uint256)
    {
        // TODO
        // Tarif structure check
        // PayWith array whiteList check
        return _addTariff(msg.sender, _newTariff);
    }

    /**
     * @notice Edit tariff for caller
     * @dev Call this method from ServiceProvider
     * for setup new tariff 
     * using `Tariff` data type(please see above)
     *
     * @param _tariffIndex  - index in `availableTariffs` array 
     * @param _timelockPeriod - see SubscriptionType notice above
     * @param _ticketValidPeriod - see SubscriptionType notice above
     * @param _counter - see SubscriptionType notice above
     * @param _isAvailable - see SubscriptionType notice above
     * @param _beneficiary - see SubscriptionType notice above
     */
    function editServiceTariff(
        uint256 _tariffIndex, 
        uint256 _timelockPeriod,
        uint256 _ticketValidPeriod,
        uint256 _counter,
        bool _isAvailable,
        address _beneficiary
    ) 
        external
    {
        // TODO
        // Tariff structure check
        // PayWith array whiteList check
        _editTariff(
            msg.sender,
            _tariffIndex, 
            _timelockPeriod,
            _ticketValidPeriod,
            _counter,
            _isAvailable,
            _beneficiary
        );

    }

    
    /**
     * @notice Add tariff PayOption for exact service
     * @dev Call this method from ServiceProvider
     * for add tariff PayOption 
     *
     * @param _tariffIndex  - index in `availableTariffs` array 
     * @param _paymentToken - see PayOption notice above
     * @param _paymentAmount - see PayOption notice above
     * @param _agentFeePercent - see PayOption notice above
     * @return last added PaymentOption index in array 
     * for _tariffIndex Tariff of caller Service Provider (msg.sender)
     */
    function addTariffPayOption(
        uint256 _tariffIndex,
        address _paymentToken,
        uint256 _paymentAmount,
        uint16 _agentFeePercent
    ) external returns(uint256)
    {
        return _addTariffPayOption(
            msg.sender,
            _tariffIndex,
            _paymentToken,
            _paymentAmount,
            _agentFeePercent
        );
    }

    /**
     * @notice Edit tariff PayOption for exact service
     * @dev Call this method from ServiceProvider
     * for edit tariff PayOption 
     *
     * @param _tariffIndex  - index in  `availableTariffs` array 
     * @param _payWithIndex  - index in `tariff.payWith` array 
     * @param _paymentToken - see PayOption notice above
     * @param _paymentAmount - see PayOption notice above
     * @param _agentFeePercent - see PayOption notice above
     * for _tariffIndex Tariff of caller Service Provider (msg.sender)
     */
    function editTariffPayOption(
        uint256 _tariffIndex,
        uint256 _payWithIndex, 
        address _paymentToken,
        uint256 _paymentAmount,
        uint16 _agentFeePercent
    ) external 
    {
        _editTariffPayOption(
            msg.sender,
            _tariffIndex,
            _payWithIndex, 
            _paymentToken,
            _paymentAmount,
            _agentFeePercent
        );
    }

    /**
     * @notice Authorize agent for caller service provider
     * @dev Call this method from ServiceProvider
     *
     * @param _agent  - address of contract that implement Agent role 
     * @param _serviceTariffIndexes  - array of index in `availableTariffs` array
     * that available for given `_agent` 
     * @return full array of actual tarifs for this agent 
     */
    function authorizeAgentForService(
        address _agent,
        uint256[] calldata _serviceTariffIndexes
    ) external virtual returns (uint256[] memory) 
    {
        // remove previouse tariffs
        delete agentServiceRegistry[msg.sender][_agent];
        uint256[] storage currentServiceTariffsOfAgent = agentServiceRegistry[msg.sender][_agent];
        // check that adding tariffs still available
        for(uint256 i; i < _serviceTariffIndexes.length; ++ i) {
            if (availableTariffs[msg.sender][_serviceTariffIndexes[i]].subscription.isAvailable){
                currentServiceTariffsOfAgent.push(_serviceTariffIndexes[i]);
            }
        }
        return currentServiceTariffsOfAgent;
    }
    
     /**
     * @notice By Ticket for subscription
     * @dev Call this method from Agent
     *
     * @param _service  - Service Provider address 
     * @param _tariffIndex  - index in  `availableTariffs` array 
     * @param _payWithIndex  - index in `tariff.payWith` array 
     * @param _buyFor - address for whome this ticket would be bought 
     * @param _payer - address of payer for this ticket
     * @return ticket structure that would be use for validate service process
     */
    function buySubscription(
        address _service,
        uint256 _tariffIndex,
        uint256 _payWithIndex,
        address _buyFor,
        address _payer
    ) external 
      payable
      returns(Ticket memory ticket) {
        // Cant buy ticket for nobody
        require(_buyFor != address(0),'Cant buy ticket for nobody');

        require(
            availableTariffs[_service][_tariffIndex].subscription.isAvailable,
            'This subscription not available'
        );

        require(
            availableTariffs[_service][_tariffIndex].payWith[_payWithIndex].paymentAmount > 0,
            'This Payment option not available'
        );

        // Check that agent is authorized for purchace of this service
        require(
            _isAgentAuthorized(msg.sender, _service, _tariffIndex), 
            'Agent not authorized for this service tariff' 
        );
        
        (bool isValid, bool needFix) = _isTicketValid(_buyFor, _service);
        require(!isValid, 'Only one valid ticket at time');

        //lets safe user ticket (only one ticket available in this version)
        ticket = Ticket(
            availableTariffs[_service][_tariffIndex].subscription.ticketValidPeriod + block.timestamp,
            availableTariffs[_service][_tariffIndex].subscription.counter
        );
        userTickets[_buyFor][_service] = ticket;

        // Lets receive payment tokens FROM sender
        _processPayment(_service, _tariffIndex, _payWithIndex, _payer);
        
        emit TicketIssued(_service, msg.sender, _buyFor, _tariffIndex);
    }

    /**
     * @notice Check that `_user` have still valid ticket for this service.
     * Decrement ticket counter in case it > 0
     * @dev Call this method from ServiceProvider
     *
     * @param _user  - address of user who has an ticket and who trying get service 
     * @return ok True in case ticket is valid
     */
    function checkAndFixUserSubscription(
        address _user
    ) external returns (bool ok){
        
        address _service = msg.sender;
        // Check user ticket
        (bool isValid, bool needFix) = _isTicketValid(_user, msg.sender);
        
        // Proxy to previos
        if (!isValid && previousRegistry != address(0)) {
            (isValid, needFix) = ISubscriptionRegistry(previousRegistry).checkUserSubscription(
                _user, 
                _service
            );
            // Case when valid ticket stored in previousManager
            if (isValid ) {
                if (needFix){
                    ISubscriptionRegistry(previousRegistry).fixUserSubscription(
                        _user, 
                        _service
                    );
                }
                ok = true;
                return ok;
            }
        }
        require(isValid,'Valid ticket not found');
        
        // Fix action (for subscription with counter)
        if (needFix){
            _fixUserSubscription(_user, msg.sender);    
        }
                
        ok = true;
    }

     /**
     * @notice Decrement ticket counter in case it > 0
     * @dev Call this method from new SubscriptionRegistry in case of upgrade
     *
     * @param _user  - address of user who has an ticket and who trying get service 
     * @param _serviceFromProxy  - address of service from more new SubscriptionRegistry contract 
     */
    function fixUserSubscription(
        address _user,
        address _serviceFromProxy
    ) public {
        require(proxyRegistry !=address(0) && msg.sender == proxyRegistry,
            'Only for future registry'
        );
        _fixUserSubscription(_user, _serviceFromProxy);
    }

    ////////////////////////////////////////////////////////////////
    
    /**
     * @notice Check that `_user` have still valid ticket for this service.
     * @dev Call this method from any context
     *
     * @param _user  - address of user who has an ticket and who trying get service 
     * @param _service - address of Service Provider
     * @return ok True in case ticket is valid
     * @return needFix True in case ticket has counter > 0
     */
    function checkUserSubscription(
        address _user, 
        address _service
    ) external view returns (bool ok, bool needFix) {
        (ok, needFix)  = _isTicketValid(_user, _service);
        if (!ok && previousRegistry != address(0)) {
            (ok, needFix) = ISubscriptionRegistry(previousRegistry).checkUserSubscription(
                _user, 
                _service
            );
        }
    }

    /**
     * @notice Returns `_user` ticket for this service.
     * @dev Call this method from any context
     *
     * @param _user  - address of user who has an ticket and who trying get service 
     * @param _service - address of Service Provider
     * @return ticket
     */
    function getUserTicketForService(
        address _service,
        address _user
    ) public view returns(Ticket memory) 
    {
        return userTickets[_user][_service];
    }

    /**
     * @notice Returns array of Tariff for `_service`
     * @dev Call this method from any context
     *
     * @param _service - address of Service Provider
     * @return Tariff array
     */
    function getTariffsForService(address _service) external view returns (Tariff[] memory) {
        return availableTariffs[_service];
    }

    /**
     * @notice Returns ticket price include any fees
     * @dev Call this method from any context
     *
     * @param _service - address of Service Provider
     * @param _tariffIndex  - index in  `availableTariffs` array 
     * @param _payWithIndex  - index in `tariff.payWith` array 
     * @return tulpe with payment token an ticket price 
     */
    function getTicketPrice(
        address _service,
        uint256 _tariffIndex,
        uint256 _payWithIndex
    ) public view virtual returns (address, uint256) 
    {
        if (availableTariffs[_service][_tariffIndex].subscription.timelockPeriod != 0)
        {
            return(
                availableTariffs[_service][_tariffIndex].payWith[_payWithIndex].paymentToken,
                availableTariffs[_service][_tariffIndex].payWith[_payWithIndex].paymentAmount
            );
        } else {
            return(
                availableTariffs[_service][_tariffIndex].payWith[_payWithIndex].paymentToken,
                availableTariffs[_service][_tariffIndex].payWith[_payWithIndex].paymentAmount
                + availableTariffs[_service][_tariffIndex].payWith[_payWithIndex].paymentAmount
                    *availableTariffs[_service][_tariffIndex].payWith[_payWithIndex].agentFeePercent
                    /PERCENT_DENOMINATOR
                + availableTariffs[_service][_tariffIndex].payWith[_payWithIndex].paymentAmount
                        *_platformFeePercent(_service, _tariffIndex, _payWithIndex) 
                        /PERCENT_DENOMINATOR
            );
        }
    }

    /**
     * @notice Returns array of Tariff for `_service` assigned to `_agent`
     * @dev Call this method from any context
     *
     * @param _agent - address of Agent
     * @param _service - address of Service Provider
     * @return Tariff array
     */
    function getAvailableAgentsTariffForService(
        address _agent, 
        address _service
    ) external view virtual returns(Tariff[] memory) 
    {
        //First need get count of tarifs that still available
        uint256 availableCount;
        for (uint256 i; i < agentServiceRegistry[_service][_agent].length; ++i){
            if (availableTariffs[_service][
                  agentServiceRegistry[_service][_agent][i]
                ].subscription.isAvailable
            ) {++availableCount;}
        }
        
        Tariff[] memory result = new Tariff[](availableCount);
        for (uint256 i; i < agentServiceRegistry[_service][_agent].length; ++i){
            if (availableTariffs[_service][
                  agentServiceRegistry[_service][_agent][i]
                ].subscription.isAvailable
            ) 
            {
                result[availableCount - 1] = availableTariffs[_service][
                  agentServiceRegistry[_service][_agent][i]
                ];
                --availableCount;
            }
        }
        return result;
    }    
    ////////////////////////////////////////////////////////////////
    //////////     Admins                                     //////
    ////////////////////////////////////////////////////////////////

    function setAssetForPaymentState(address _asset, bool _isEnable)
        external onlyOwner 
    {
        whiteListedForPayments[_asset] = _isEnable;
        emit WhitelistPaymentTokenChanged(_asset, _isEnable);
    }

    function setMainWrapper(address _wrapper) external onlyOwner {
        mainWrapper = _wrapper;
    }

    function setPlatformOwner(address _newOwner) external {
        require(msg.sender == platformOwner, 'Only platform owner');
        require(_newOwner != address(0),'Zero platform fee receiver');
        platformOwner = _newOwner;
    }

    function setPlatformFeePercent(uint16 _newPercent) external {
        require(msg.sender == platformOwner, 'Only platform owner');
        platformFeePercent = _newPercent;
        emit PlatfromFeeChanged(platformFeePercent);
    }

    

    function setPreviousRegistry(address _registry) external onlyOwner {
        previousRegistry = _registry;
    }

    function setProxyRegistry(address _registry) external onlyOwner {
        proxyRegistry = _registry;
    }
    /////////////////////////////////////////////////////////////////////
    
    function _processPayment(
        address _service,
        uint256 _tariffIndex,
        uint256 _payWithIndex,
        address _payer
    ) 
        internal 
        virtual 
        returns(bool)
    {
        // there are two payment method for this implementation.
        // 1. with wrap and lock in asset (no fees)
        // 2. simple payment (agent & platform fee enabled)
        if (availableTariffs[_service][_tariffIndex].subscription.timelockPeriod != 0){
            require(msg.value == 0, 'Ether Not accepted in this method');
            // 1. with wrap and lock in asset
            IERC20(
                availableTariffs[_service][_tariffIndex].payWith[_payWithIndex].paymentToken
            ).safeTransferFrom(
                _payer, 
                address(this),
                availableTariffs[_service][_tariffIndex].payWith[_payWithIndex].paymentAmount
            );

            // Lets approve received for wrap 
            IERC20(
                availableTariffs[_service][_tariffIndex].payWith[_payWithIndex].paymentToken
            ).safeApprove(
                mainWrapper,
                availableTariffs[_service][_tariffIndex].payWith[_payWithIndex].paymentAmount
            );

            // Lets wrap with timelock and appropriate params
            ETypes.INData memory _inData;
            ETypes.AssetItem[] memory _collateralERC20 = new ETypes.AssetItem[](1);
            ETypes.Lock[] memory timeLock =  new ETypes.Lock[](1);
            // Only need set timelock for this wNFT
            timeLock[0] = ETypes.Lock(
                0x00, // timelock
                availableTariffs[_service][_tariffIndex].subscription.timelockPeriod + block.timestamp
            ); 
            _inData = ETypes.INData(
                ETypes.AssetItem(
                    ETypes.Asset(ETypes.AssetType.EMPTY, address(0)),
                    0,0
                ),          // INAsset
                address(0), // Unwrap destinition    
                new ETypes.Fee[](0), // Fees
                //new ETypes.Lock[](0), // Locks
                timeLock,
                new ETypes.Royalty[](0), // Royalties
                ETypes.AssetType.ERC721, // Out type
                0, // Out Balance
                0x0000 // Rules
            );

            _collateralERC20[0] = ETypes.AssetItem(
                ETypes.Asset(
                    ETypes.AssetType.ERC20,
                    availableTariffs[_service][_tariffIndex].payWith[_payWithIndex].paymentToken
                ),
                0,
                availableTariffs[_service][_tariffIndex].payWith[_payWithIndex].paymentAmount
            );
            
            ITrustedWrapper(mainWrapper).wrap(
                _inData,
                _collateralERC20,
                _payer
            );

        } else {
            // 2. simple payment
            if (availableTariffs[_service][_tariffIndex]
                .payWith[_payWithIndex]
                .paymentToken != address(0)
            ) 
            {
                // pay with erc20 
                require(msg.value == 0, 'Ether Not accepted in this method');
                // 2.1. Body payment  
                IERC20(
                    availableTariffs[_service][_tariffIndex].payWith[_payWithIndex].paymentToken
                ).safeTransferFrom(
                    _payer, 
                    availableTariffs[_service][_tariffIndex].subscription.beneficiary,
                    availableTariffs[_service][_tariffIndex].payWith[_payWithIndex].paymentAmount
                );

                // 2.2. Agent fee payment
                IERC20(
                    availableTariffs[_service][_tariffIndex].payWith[_payWithIndex].paymentToken
                ).safeTransferFrom(
                    _payer, 
                    msg.sender,
                    availableTariffs[_service][_tariffIndex].payWith[_payWithIndex].paymentAmount
                     *availableTariffs[_service][_tariffIndex].payWith[_payWithIndex].agentFeePercent
                     /PERCENT_DENOMINATOR
                );

                // 2.3. Platform fee 
                uint256 _pFee = _platformFeePercent(_service, _tariffIndex, _payWithIndex); 
                if (_pFee > 0) {
                    IERC20(
                        availableTariffs[_service][_tariffIndex].payWith[_payWithIndex].paymentToken
                    ).safeTransferFrom(
                        _payer, 
                        platformOwner, //
                        availableTariffs[_service][_tariffIndex].payWith[_payWithIndex].paymentAmount
                          *_pFee
                          /PERCENT_DENOMINATOR
                    );
                }

            } else {
                // pay with native token(eth, bnb, etc)
                (, uint256 needPay) = getTicketPrice(_service, _tariffIndex,_payWithIndex);
                require(msg.value >= needPay, 'Not enough ether');
                // 2.4. Body ether payment
                sendValue(
                    payable(availableTariffs[_service][_tariffIndex].subscription.beneficiary),
                    availableTariffs[_service][_tariffIndex].payWith[_payWithIndex].paymentAmount
                );

                // 2.5. Agent fee payment
                sendValue(
                    payable(msg.sender),
                    availableTariffs[_service][_tariffIndex].payWith[_payWithIndex].paymentAmount
                      *availableTariffs[_service][_tariffIndex].payWith[_payWithIndex].agentFeePercent
                      /PERCENT_DENOMINATOR
                );

                // 2.3. Platform fee 
                uint256 _pFee = _platformFeePercent(_service, _tariffIndex, _payWithIndex); 
                if (_pFee > 0) {

                    sendValue(
                        payable(platformOwner),
                        availableTariffs[_service][_tariffIndex].payWith[_payWithIndex].paymentAmount
                          *_pFee
                          /PERCENT_DENOMINATOR
                    );
                }
                // return change
                if  ((msg.value - needPay) > 0) {
                    address payable s = payable(_payer);
                    s.transfer(msg.value - needPay);
                }
            }
        }
    }

    // In this impementation params not used. 
    // Can be ovveriden in other cases
    function _platformFeePercent(
        address _service, 
        uint256 _tariffIndex, 
        uint256  _payWithIndex
    ) internal view virtual returns(uint256) 
    {
        return platformFeePercent;
    }

    function _addTariff(address _service, Tariff calldata _newTariff) 
        internal returns(uint256) 
    {
        require (_newTariff.payWith.length > 0, 'No payment method');
        for (uint256 i; i < _newTariff.payWith.length; ++i){
            require(
                whiteListedForPayments[_newTariff.payWith[i].paymentToken],
                'Not whitelisted for payments'
            );      
        }
        require(
            _newTariff.subscription.ticketValidPeriod > 0 
            || _newTariff.subscription.counter > 0,
            'Tariff has no valid ticket option'  
        );
        availableTariffs[_service].push(_newTariff);
        emit TariffChanged(_service, availableTariffs[_service].length - 1);
        return availableTariffs[_service].length - 1;
    }


    function _editTariff(
        address _service,
        uint256 _tariffIndex, 
        uint256 _timelockPeriod,
        uint256 _ticketValidPeriod,
        uint256 _counter,
        bool _isAvailable,
        address _beneficiary
    ) internal  
    {
        availableTariffs[_service][_tariffIndex].subscription.timelockPeriod    = _timelockPeriod;
        availableTariffs[_service][_tariffIndex].subscription.ticketValidPeriod = _ticketValidPeriod;
        availableTariffs[_service][_tariffIndex].subscription.counter = _counter;
        availableTariffs[_service][_tariffIndex].subscription.isAvailable = _isAvailable;    
        availableTariffs[_service][_tariffIndex].subscription.beneficiary = _beneficiary;    
        emit TariffChanged(_service, _tariffIndex);
    }
   
    function _addTariffPayOption(
        address _service,
        uint256 _tariffIndex,
        address _paymentToken,
        uint256 _paymentAmount,
        uint16 _agentFeePercent
    ) internal returns(uint256)
    {
        require(whiteListedForPayments[_paymentToken], 'Not whitelisted for payments');
        availableTariffs[_service][_tariffIndex].payWith.push(
            PayOption(_paymentToken, _paymentAmount, _agentFeePercent)
        ); 
        emit TariffChanged(_service, _tariffIndex);
        return availableTariffs[_service][_tariffIndex].payWith.length - 1;
    }

    function _editTariffPayOption(
        address _service,
        uint256 _tariffIndex,
        uint256 _payWithIndex, 
        address _paymentToken,
        uint256 _paymentAmount,
        uint16 _agentFeePercent
    ) internal  
    {
        require(whiteListedForPayments[_paymentToken], 'Not whitelisted for payments');
        availableTariffs[_service][_tariffIndex].payWith[_payWithIndex] 
        = PayOption(_paymentToken, _paymentAmount, _agentFeePercent);  
        emit TariffChanged(_service, _tariffIndex);  
    }

    function _fixUserSubscription(
        address _user,
        address _service
    ) internal {
       
        // Fix action (for subscription with counter)
        if (userTickets[_user][_service].countsLeft > 0) {
            -- userTickets[_user][_service].countsLeft; 
        }
    }

        
   function _isTicketValid(address _user, address _service) 
        internal 
        view 
        returns (bool isValid, bool needFix ) 
    {
        isValid =  userTickets[_user][_service].validUntil > block.timestamp 
            || userTickets[_user][_service].countsLeft > 0;
        needFix =  userTickets[_user][_service].countsLeft > 0;   
    }

    function _isAgentAuthorized(
        address _agent, 
        address _service, 
        uint256 _tariffIndex
    ) 
        internal
        view
        returns(bool authorized)
    {
        for (uint256 i; i < agentServiceRegistry[_service][_agent].length; ++ i){
            if (agentServiceRegistry[_service][_agent][i] == _tariffIndex){
                authorized = true;
                return authorized;
            }
        }
    }

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

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

pragma solidity 0.8.16;

import "IWrapper.sol";

interface ITrustedWrapper is IWrapper  {

    function trustedOperator() external view returns(address);    
    
    function wrapUnsafe(
        ETypes.INData calldata _inData, 
        ETypes.AssetItem[] calldata _collateral, 
        address _wrappFor
    ) 
        external
        payable
        returns (ETypes.AssetItem memory); 

    function transferIn(
        ETypes.AssetItem memory _assetItem,
        address _from
    ) 
        external
        payable  
    returns (uint256 _transferedValue);
   
}

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

Contract ABI

[{"inputs":[{"internalType":"address","name":"_subscrRegistry","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[{"internalType":"address[]","name":"_wNFTAddress","type":"address[]"},{"internalType":"uint256[]","name":"_wNFTTokenId","type":"uint256[]"},{"components":[{"components":[{"internalType":"enum ETypes.AssetType","name":"assetType","type":"uint8"},{"internalType":"address","name":"contractAddress","type":"address"}],"internalType":"struct ETypes.Asset","name":"asset","type":"tuple"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct ETypes.AssetItem[]","name":"_collateralERC20","type":"tuple[]"}],"name":"addCollateralBatch","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tariffIndex","type":"uint256"},{"internalType":"address","name":"_paymentToken","type":"address"},{"internalType":"uint256","name":"_paymentAmount","type":"uint256"},{"internalType":"uint16","name":"_agentFeePercent","type":"uint16"}],"name":"addPayOption","outputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_agent","type":"address"},{"internalType":"uint256[]","name":"_serviceTariffIndexes","type":"uint256[]"}],"name":"authAgent","outputs":[{"internalType":"uint256[]","name":"actualTariffs","type":"uint256[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_user","type":"address"}],"name":"checkUser","outputs":[{"internalType":"bool","name":"ok","type":"bool"},{"internalType":"bool","name":"needFix","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tariffIndex","type":"uint256"},{"internalType":"uint256","name":"_payWithIndex","type":"uint256"},{"internalType":"address","name":"_paymentToken","type":"address"},{"internalType":"uint256","name":"_paymentAmount","type":"uint256"},{"internalType":"uint16","name":"_agentFeePercent","type":"uint16"}],"name":"editPayOption","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tariffIndex","type":"uint256"},{"internalType":"uint256","name":"_timelockPeriod","type":"uint256"},{"internalType":"uint256","name":"_ticketValidPeriod","type":"uint256"},{"internalType":"uint256","name":"_counter","type":"uint256"},{"internalType":"bool","name":"_isAvailable","type":"bool"},{"internalType":"address","name":"_beneficiary","type":"address"}],"name":"editTariff","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"components":[{"internalType":"uint256","name":"timelockPeriod","type":"uint256"},{"internalType":"uint256","name":"ticketValidPeriod","type":"uint256"},{"internalType":"uint256","name":"counter","type":"uint256"},{"internalType":"bool","name":"isAvailable","type":"bool"},{"internalType":"address","name":"beneficiary","type":"address"}],"internalType":"struct SubscriptionType","name":"subscription","type":"tuple"},{"components":[{"internalType":"address","name":"paymentToken","type":"address"},{"internalType":"uint256","name":"paymentAmount","type":"uint256"},{"internalType":"uint16","name":"agentFeePercent","type":"uint16"}],"internalType":"struct PayOption[]","name":"payWith","type":"tuple[]"}],"internalType":"struct Tariff","name":"_newTariff","type":"tuple"}],"name":"newTariff","outputs":[{"internalType":"uint256","name":"tariffIndex","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"serviceProvider","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_subscrRegistry","type":"address"}],"name":"setSubscriptionRegestry","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_wrapper","type":"address"}],"name":"setTrustedWrapper","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"subscriptionRegistry","outputs":[{"internalType":"contract ISubscriptionRegistry","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"trustedWrapper","outputs":[{"internalType":"contract ITrustedWrapperV2","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"components":[{"components":[{"internalType":"enum ETypes.AssetType","name":"assetType","type":"uint8"},{"internalType":"address","name":"contractAddress","type":"address"}],"internalType":"struct ETypes.Asset","name":"asset","type":"tuple"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct ETypes.AssetItem","name":"inAsset","type":"tuple"},{"internalType":"address","name":"unWrapDestination","type":"address"},{"components":[{"internalType":"bytes1","name":"feeType","type":"bytes1"},{"internalType":"uint256","name":"param","type":"uint256"},{"internalType":"address","name":"token","type":"address"}],"internalType":"struct ETypes.Fee[]","name":"fees","type":"tuple[]"},{"components":[{"internalType":"bytes1","name":"lockType","type":"bytes1"},{"internalType":"uint256","name":"param","type":"uint256"}],"internalType":"struct ETypes.Lock[]","name":"locks","type":"tuple[]"},{"components":[{"internalType":"address","name":"beneficiary","type":"address"},{"internalType":"uint16","name":"percent","type":"uint16"}],"internalType":"struct ETypes.Royalty[]","name":"royalties","type":"tuple[]"},{"internalType":"enum ETypes.AssetType","name":"outType","type":"uint8"},{"internalType":"uint256","name":"outBalance","type":"uint256"},{"internalType":"bytes2","name":"rules","type":"bytes2"}],"internalType":"struct ETypes.INData[]","name":"_inDataS","type":"tuple[]"},{"components":[{"components":[{"internalType":"enum ETypes.AssetType","name":"assetType","type":"uint8"},{"internalType":"address","name":"contractAddress","type":"address"}],"internalType":"struct ETypes.Asset","name":"asset","type":"tuple"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct ETypes.AssetItem[]","name":"_collateralERC20","type":"tuple[]"},{"internalType":"address[]","name":"_receivers","type":"address[]"}],"name":"wrapBatch","outputs":[],"stateMutability":"payable","type":"function"}]

60806040523480156200001157600080fd5b50604051620024c4380380620024c4833981016040819052620000349162000110565b806200004033620000c0565b6001600160a01b0381166200008b5760405162461bcd60e51b815260206004820152600d60248201526c4e6f6e207a65726f206f6e6c7960981b604482015260640160405180910390fd5b60018054306001600160a01b031991821617909155600280549091166001600160a01b03929092169190911790555062000142565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6000602082840312156200012357600080fd5b81516001600160a01b03811681146200013b57600080fd5b9392505050565b61237280620001526000396000f3fe6080604052600436106100f35760003560e01c8063715018a61161008a578063adae3ebf11610059578063adae3ebf14610295578063b22aa669146102b5578063f2fde38b146102e2578063fb8adca41461030257600080fd5b8063715018a61461022f578063796352d6146102445780638d69e95e146102575780638da5cb5b1461027757600080fd5b80635b3f9c6e116100c65780635b3f9c6e146101bc57806363c7832b146101dc57806368a2b580146101ef5780636f1c15671461020f57600080fd5b80630c5620d6146100f85780631e9d48cf1461012b57806320da7170146101625780635751869b1461019a575b600080fd5b34801561010457600080fd5b5061011861011336600461160f565b610322565b6040519081526020015b60405180910390f35b34801561013757600080fd5b5061014b6101463660046116dc565b61033b565b604080519215158352901515602083015201610122565b34801561016e57600080fd5b50600254610182906001600160a01b031681565b6040516001600160a01b039091168152602001610122565b3480156101a657600080fd5b506101ba6101b53660046116f9565b610350565b005b3480156101c857600080fd5b506101ba6101d73660046116dc565b61036c565b6101ba6101ea3660046117da565b610396565b3480156101fb57600080fd5b506101ba61020a366004611873565b610630565b34801561021b57600080fd5b506101ba61022a3660046116dc565b61064e565b34801561023b57600080fd5b506101ba610719565b6101ba6102523660046118d1565b61072d565b34801561026357600080fd5b50600154610182906001600160a01b031681565b34801561028357600080fd5b506000546001600160a01b0316610182565b3480156102a157600080fd5b50600354610182906001600160a01b031681565b3480156102c157600080fd5b506102d56102d03660046119c3565b610c6b565b6040516101229190611aa3565b3480156102ee57600080fd5b506101ba6102fd3660046116dc565b610c86565b34801561030e57600080fd5b5061011861031d366004611ab6565b610cfc565b600061032c610d1b565b61033582610d75565b92915050565b60008061034783610de8565b91509150915091565b610358610d1b565b6103658585858585610e69565b5050505050565b610374610d1b565b600280546001600160a01b0319166001600160a01b0392909216919091179055565b61039f33610ee3565b508483146103c85760405162461bcd60e51b81526004016103bf90611afe565b60405180910390fd5b60005b818110156104ff5760028383838181106103e7576103e7611b57565b6103fd9260206080909202019081019150611b85565b600781111561040e5761040e611b41565b036104ed5761047b33308886868681811061042b5761042b611b57565b9050608002016060013561043f9190611bb8565b86868681811061045157610451611b57565b61046a92604060809092020190810191506020016116dc565b6001600160a01b0316929190610f54565b6003546104ed906001600160a01b03168785858581811061049e5761049e611b57565b905060800201606001356104b29190611bb8565b8585858181106104c4576104c4611b57565b6104dd92604060809092020190810191506020016116dc565b6001600160a01b03169190610fc5565b806104f781611bd7565b9150506103cb565b50600061050c8634611bf0565b905060005b868110156105d1576003546001600160a01b03166391ddb146838a8a8581811061053d5761053d611b57565b905060200201602081019061055291906116dc565b89898681811061056457610564611b57565b9050602002013588886040518663ffffffff1660e01b815260040161058c9493929190611cb9565b6000604051808303818588803b1580156105a557600080fd5b505af11580156105b9573d6000803e3d6000fd5b505050505080806105c990611bd7565b915050610511565b50346105dd8783611bb8565b10156106275733806108fc6105f28985611bb8565b6105fc9034611ceb565b6040518115909202916000818181858888f19350505050158015610624573d6000803e3d6000fd5b50505b50505050505050565b610638610d1b565b610646868686868686611077565b505050505050565b610656610d1b565b600380546001600160a01b0319166001600160a01b03831690811790915560405163146d77bb60e21b81523060048201526351b5deec90602401602060405180830381865afa1580156106ad573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106d19190611cfe565b6107165760405162461bcd60e51b815260206004820152601660248201527527b7363c903337b91032bc30b1ba103bb930b83832b960511b60448201526064016103bf565b50565b610721610d1b565b61072b6000611102565b565b61073633610ee3565b50805184146107575760405162461bcd60e51b81526004016103bf90611afe565b60005b8481101561096d5760035482516001600160a01b0390911690639a251c29906107839034611bf0565b88888581811061079557610795611b57565b90506020028101906107a79190611d1b565b87878787815181106107bb576107bb611b57565b60200260200101516040518663ffffffff1660e01b81526004016107e29493929190611efb565b60806040518083038185885af1158015610800573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906108259190612021565b50600386868381811061083a5761083a611b57565b905060200281019061084c9190611d1b565b61085a906020810190611b85565b600781111561086b5761086b611b41565b14806108b95750600486868381811061088657610886611b57565b90506020028101906108989190611d1b565b6108a6906020810190611b85565b60078111156108b7576108b7611b41565b145b1561095b576003546001600160a01b03166397da0ceb8787848181106108e1576108e1611b57565b90506020028101906108f39190611d1b565b6040516001600160e01b031960e084901b16815261091691903390600401612098565b6020604051808303816000875af1158015610935573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061095991906120be565b505b8061096581611bd7565b91505061075a565b506040805160a0810182526000606082018181526080830182905282526020820181905291810182905290805b84811015610c1b5760028686838181106109b6576109b6611b57565b6109cc9260206080909202019081019150611b85565b60078111156109dd576109dd611b41565b03610b94578585828181106109f4576109f4611b57565b610a0a9260206080909202019081019150611b85565b8351906007811115610a1e57610a1e611b41565b90816007811115610a3157610a31611b41565b905250858582818110610a4657610a46611b57565b610a5f92604060809092020190810191506020016116dc565b83516001600160a01b03909116602090910152858582818110610a8457610a84611b57565b905060800201604001358360200181815250508351868683818110610aab57610aab611b57565b90506080020160600135610abf9190611bb8565b60408085019190915260035490516397da0ceb60e01b81526000916001600160a01b0316906397da0ceb90610afa90879033906004016120d7565b6020604051808303816000875af1158015610b19573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b3d91906120be565b905083604001518114610b925760405162461bcd60e51b815260206004820181905260248201527f436865636b207472616e7366657220455243323020616d6f756e74206661696c60448201526064016103bf565b505b6001868683818110610ba857610ba8611b57565b610bbe9260206080909202019081019150611b85565b6007811115610bcf57610bcf611b41565b03610c09578351868683818110610be857610be8611b57565b90506080020160600135610bfc9190611bb8565b610c069083612127565b91505b80610c1381611bd7565b91505061099a565b503481146106275760405162461bcd60e51b815260206004820152601a60248201527f4e617469766520616d6f756e7420636865636b206661696c656400000000000060448201526064016103bf565b6060610c75610d1b565b610c7f8383611152565b9392505050565b610c8e610d1b565b6001600160a01b038116610cf35760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016103bf565b61071681611102565b6000610d06610d1b565b610d12858585856111cc565b95945050505050565b6000546001600160a01b0316331461072b5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016103bf565b6002546040516278451d60e81b81526000916001600160a01b0316906378451d0090610da590859060040161213a565b6020604051808303816000875af1158015610dc4573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061033591906120be565b60025460405163496d511d60e11b81526001600160a01b03838116600483015230602483015260009283929116906392daa23a906044016040805180830381865afa158015610e3b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e5f91906121f0565b9094909350915050565b60025460405163650aac6160e01b815260048101879052602481018690526001600160a01b0385811660448301526064820185905261ffff841660848301529091169063650aac619060a401600060405180830381600087803b158015610ecf57600080fd5b505af1158015610624573d6000803e3d6000fd5b600254604051632e5f2cf160e01b81526001600160a01b0383811660048301526000921690632e5f2cf1906024016020604051808303816000875af1158015610f30573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103359190611cfe565b6040516001600160a01b0380851660248301528316604482015260648101829052610fbf9085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915261125d565b50505050565b604051636eb1769f60e11b81523060048201526001600160a01b038381166024830152600091839186169063dd62ed3e90604401602060405180830381865afa158015611016573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061103a91906120be565b6110449190612127565b6040516001600160a01b038516602482015260448101829052909150610fbf90859063095ea7b360e01b90606401610f88565b600254604051631f16aef360e01b81526004810188905260248101879052604481018690526064810185905283151560848201526001600160a01b0383811660a483015290911690631f16aef39060c401600060405180830381600087803b1580156110e257600080fd5b505af11580156110f6573d6000803e3d6000fd5b50505050505050505050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60025460405163a3fafd0560e01b81526060916001600160a01b03169063a3fafd0590611185908690869060040161222a565b6000604051808303816000875af11580156111a4573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610c7f919081019061224e565b600254604051639aab948160e01b8152600481018690526001600160a01b0385811660248301526044820185905261ffff841660648301526000921690639aab9481906084016020604051808303816000875af1158015611231573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d1291906120be565b949350505050565b60006112b2826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166113349092919063ffffffff16565b80519091501561132f57808060200190518101906112d09190611cfe565b61132f5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016103bf565b505050565b6060611255848460008585600080866001600160a01b0316858760405161135b91906122f7565b60006040518083038185875af1925050503d8060008114611398576040519150601f19603f3d011682016040523d82523d6000602084013e61139d565b606091505b50915091506113ae878383876113b9565b979650505050505050565b60608315611428578251600003611421576001600160a01b0385163b6114215760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016103bf565b5081611255565b611255838381511561143d5781518083602001fd5b8060405162461bcd60e51b81526004016103bf9190612309565b634e487b7160e01b600052604160045260246000fd5b604051606081016001600160401b038111828210171561148f5761148f611457565b60405290565b604080519081016001600160401b038111828210171561148f5761148f611457565b60405160a081016001600160401b038111828210171561148f5761148f611457565b604051601f8201601f191681016001600160401b038111828210171561150157611501611457565b604052919050565b801515811461071657600080fd5b6001600160a01b038116811461071657600080fd5b60006001600160401b0382111561154557611545611457565b5060051b60200190565b803561ffff8116811461156157600080fd5b919050565b600082601f83011261157757600080fd5b8135602061158c6115878361152c565b6114d9565b828152606092830285018201928282019190878511156115ab57600080fd5b8387015b858110156116025781818a0312156115c75760008081fd5b6115cf61146d565b81356115da81611517565b8152818601358682015260406115f181840161154f565b9082015284529284019281016115af565b5090979650505050505050565b60006020828403121561162157600080fd5b81356001600160401b038082111561163857600080fd5b9083019081850360c081121561164d57600080fd5b611655611495565b60a082121561166357600080fd5b61166b6114b7565b9150833582526020840135602083015260408401356040830152606084013561169381611509565b606083015260808401356116a681611517565b608083015290815260a083013590828211156116c157600080fd5b6116cd87838601611566565b60208201529695505050505050565b6000602082840312156116ee57600080fd5b8135610c7f81611517565b600080600080600060a0868803121561171157600080fd5b8535945060208601359350604086013561172a81611517565b92506060860135915061173f6080870161154f565b90509295509295909350565b60008083601f84011261175d57600080fd5b5081356001600160401b0381111561177457600080fd5b6020830191508360208260051b850101111561178f57600080fd5b9250929050565b60008083601f8401126117a857600080fd5b5081356001600160401b038111156117bf57600080fd5b6020830191508360208260071b850101111561178f57600080fd5b600080600080600080606087890312156117f357600080fd5b86356001600160401b038082111561180a57600080fd5b6118168a838b0161174b565b9098509650602089013591508082111561182f57600080fd5b61183b8a838b0161174b565b9096509450604089013591508082111561185457600080fd5b5061186189828a01611796565b979a9699509497509295939492505050565b60008060008060008060c0878903121561188c57600080fd5b8635955060208701359450604087013593506060870135925060808701356118b381611509565b915060a08701356118c381611517565b809150509295509295509295565b6000806000806000606086880312156118e957600080fd5b85356001600160401b038082111561190057600080fd5b61190c89838a0161174b565b909750955060209150878201358181111561192657600080fd5b6119328a828b01611796565b90965094505060408801358181111561194a57600080fd5b88019050601f8101891361195d57600080fd5b803561196b6115878261152c565b81815260059190911b8201830190838101908b83111561198a57600080fd5b928401925b828410156119b15783356119a281611517565b8252928401929084019061198f565b80955050505050509295509295909350565b600080604083850312156119d657600080fd5b82356119e181611517565b91506020838101356001600160401b038111156119fd57600080fd5b8401601f81018613611a0e57600080fd5b8035611a1c6115878261152c565b81815260059190911b82018301908381019088831115611a3b57600080fd5b928401925b82841015611a5957833582529284019290840190611a40565b80955050505050509250929050565b600081518084526020808501945080840160005b83811015611a9857815187529582019590820190600101611a7c565b509495945050505050565b602081526000610c7f6020830184611a68565b60008060008060808587031215611acc57600080fd5b843593506020850135611ade81611517565b925060408501359150611af36060860161154f565b905092959194509250565b60208082526023908201527f417272617920706172616d73206d757374206861766520657175616c206c656e6040820152620cee8d60eb1b606082015260800190565b634e487b7160e01b600052602160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b6008811061071657600080fd5b803561156181611b6d565b600060208284031215611b9757600080fd5b8135610c7f81611b6d565b634e487b7160e01b600052601160045260246000fd5b6000816000190483118215151615611bd257611bd2611ba2565b500290565b600060018201611be957611be9611ba2565b5060010190565b600082611c0d57634e487b7160e01b600052601260045260246000fd5b500490565b60088110611c3057634e487b7160e01b600052602160045260246000fd5b9052565b8035611c3f81611b6d565b611c498382611c12565b506020810135611c5881611517565b6001600160a01b0316602083015260408181013590830152606090810135910152565b81835260208301925060008160005b84811015611caf57611c9c8683611c34565b6080958601959190910190600101611c8a565b5093949350505050565b60018060a01b0385168152836020820152606060408201526000611ce1606083018486611c7b565b9695505050505050565b8181038181111561033557610335611ba2565b600060208284031215611d1057600080fd5b8151610c7f81611509565b6000823561015e19833603018112611d3257600080fd5b9190910192915050565b6000808335601e19843603018112611d5357600080fd5b83016020810192503590506001600160401b03811115611d7257600080fd5b60608102360382131561178f57600080fd5b80356001600160f81b03198116811461156157600080fd5b8183526000602080850194508260005b85811015611a98576001600160f81b0319611dc683611d84565b1687528282013583880152604080830135611de081611517565b6001600160a01b0316908801526060968701969190910190600101611dac565b6000808335601e19843603018112611e1757600080fd5b83016020810192503590506001600160401b03811115611e3657600080fd5b8060061b360382131561178f57600080fd5b8183526000602080850194508260005b85811015611a98576001600160f81b0319611e7283611d84565b168752818301358388015260409687019690910190600101611e58565b8183526000602080850194508260005b85811015611a98578135611eb281611517565b6001600160a01b0316875261ffff611ecb83850161154f565b16878401526040968701969190910190600101611e9f565b80356001600160f01b03198116811461156157600080fd5b60608152611f0c6060820186611c34565b60006080860135611f1c81611517565b6001600160a01b031660e0830152611f3760a0870187611d3c565b6101606101008181870152611f516101c087018486611d9c565b9350611f6060c08b018b611e00565b9350605f196101208189880301818a0152611f7c878785611e48565b9650611f8b60e08e018e611e00565b96509250610140828a890301818b0152611fa6888886611e8f565b9750611fb3858f01611b7a565b9650611fc1868b0188611c12565b818e01356101808b0152611fd6818f01611ee3565b9650505050505050611ff56101a08501826001600160f01b0319169052565b508281036020840152612009818688611c7b565b915050610d1260408301846001600160a01b03169052565b6000818303608081121561203457600080fd5b61203c61146d565b604082121561204a57600080fd5b612052611495565b9150835161205f81611b6d565b8252602084015161206f81611517565b806020840152508181526040840151602082015260608401516040820152809250505092915050565b60a081016120a68285611c34565b6001600160a01b039290921660809190910152919050565b6000602082840312156120d057600080fd5b5051919050565b600060a08201905083516120ec838251611c12565b6020908101516001600160a01b0390811684830152908501516040808501919091529094015160608301529190921660809092019190915290565b8082018082111561033557610335611ba2565b602080825282518051838301528082015160408085019190915280820151606080860191909152808301511515608080870191909152909201516001600160a01b0390811660a08601528584015160c080870152805160e08701819052600095949185019386939290916101008901905b808610156121e2578651805186168352888101518984015284015161ffff16848301529587019560019590950194908201906121ab565b509998505050505050505050565b6000806040838503121561220357600080fd5b825161220e81611509565b602084015190925061221f81611509565b809150509250929050565b6001600160a01b038316815260406020820181905260009061125590830184611a68565b6000602080838503121561226157600080fd5b82516001600160401b0381111561227757600080fd5b8301601f8101851361228857600080fd5b80516122966115878261152c565b81815260059190911b820183019083810190878311156122b557600080fd5b928401925b828410156113ae578351825292840192908401906122ba565b60005b838110156122ee5781810151838201526020016122d6565b50506000910152565b60008251611d328184602087016122d3565b60208152600082518060208401526123288160408501602087016122d3565b601f01601f1916919091016040019291505056fea264697066735822122028f37411c95aa3e50ccd1ef8884ea49135d2f2e71b406d69887d3f24b9fbb01a64736f6c63430008100033000000000000000000000000825f886d9116170ba5e8e70132ba72d883c079fe

Deployed Bytecode

0x6080604052600436106100f35760003560e01c8063715018a61161008a578063adae3ebf11610059578063adae3ebf14610295578063b22aa669146102b5578063f2fde38b146102e2578063fb8adca41461030257600080fd5b8063715018a61461022f578063796352d6146102445780638d69e95e146102575780638da5cb5b1461027757600080fd5b80635b3f9c6e116100c65780635b3f9c6e146101bc57806363c7832b146101dc57806368a2b580146101ef5780636f1c15671461020f57600080fd5b80630c5620d6146100f85780631e9d48cf1461012b57806320da7170146101625780635751869b1461019a575b600080fd5b34801561010457600080fd5b5061011861011336600461160f565b610322565b6040519081526020015b60405180910390f35b34801561013757600080fd5b5061014b6101463660046116dc565b61033b565b604080519215158352901515602083015201610122565b34801561016e57600080fd5b50600254610182906001600160a01b031681565b6040516001600160a01b039091168152602001610122565b3480156101a657600080fd5b506101ba6101b53660046116f9565b610350565b005b3480156101c857600080fd5b506101ba6101d73660046116dc565b61036c565b6101ba6101ea3660046117da565b610396565b3480156101fb57600080fd5b506101ba61020a366004611873565b610630565b34801561021b57600080fd5b506101ba61022a3660046116dc565b61064e565b34801561023b57600080fd5b506101ba610719565b6101ba6102523660046118d1565b61072d565b34801561026357600080fd5b50600154610182906001600160a01b031681565b34801561028357600080fd5b506000546001600160a01b0316610182565b3480156102a157600080fd5b50600354610182906001600160a01b031681565b3480156102c157600080fd5b506102d56102d03660046119c3565b610c6b565b6040516101229190611aa3565b3480156102ee57600080fd5b506101ba6102fd3660046116dc565b610c86565b34801561030e57600080fd5b5061011861031d366004611ab6565b610cfc565b600061032c610d1b565b61033582610d75565b92915050565b60008061034783610de8565b91509150915091565b610358610d1b565b6103658585858585610e69565b5050505050565b610374610d1b565b600280546001600160a01b0319166001600160a01b0392909216919091179055565b61039f33610ee3565b508483146103c85760405162461bcd60e51b81526004016103bf90611afe565b60405180910390fd5b60005b818110156104ff5760028383838181106103e7576103e7611b57565b6103fd9260206080909202019081019150611b85565b600781111561040e5761040e611b41565b036104ed5761047b33308886868681811061042b5761042b611b57565b9050608002016060013561043f9190611bb8565b86868681811061045157610451611b57565b61046a92604060809092020190810191506020016116dc565b6001600160a01b0316929190610f54565b6003546104ed906001600160a01b03168785858581811061049e5761049e611b57565b905060800201606001356104b29190611bb8565b8585858181106104c4576104c4611b57565b6104dd92604060809092020190810191506020016116dc565b6001600160a01b03169190610fc5565b806104f781611bd7565b9150506103cb565b50600061050c8634611bf0565b905060005b868110156105d1576003546001600160a01b03166391ddb146838a8a8581811061053d5761053d611b57565b905060200201602081019061055291906116dc565b89898681811061056457610564611b57565b9050602002013588886040518663ffffffff1660e01b815260040161058c9493929190611cb9565b6000604051808303818588803b1580156105a557600080fd5b505af11580156105b9573d6000803e3d6000fd5b505050505080806105c990611bd7565b915050610511565b50346105dd8783611bb8565b10156106275733806108fc6105f28985611bb8565b6105fc9034611ceb565b6040518115909202916000818181858888f19350505050158015610624573d6000803e3d6000fd5b50505b50505050505050565b610638610d1b565b610646868686868686611077565b505050505050565b610656610d1b565b600380546001600160a01b0319166001600160a01b03831690811790915560405163146d77bb60e21b81523060048201526351b5deec90602401602060405180830381865afa1580156106ad573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106d19190611cfe565b6107165760405162461bcd60e51b815260206004820152601660248201527527b7363c903337b91032bc30b1ba103bb930b83832b960511b60448201526064016103bf565b50565b610721610d1b565b61072b6000611102565b565b61073633610ee3565b50805184146107575760405162461bcd60e51b81526004016103bf90611afe565b60005b8481101561096d5760035482516001600160a01b0390911690639a251c29906107839034611bf0565b88888581811061079557610795611b57565b90506020028101906107a79190611d1b565b87878787815181106107bb576107bb611b57565b60200260200101516040518663ffffffff1660e01b81526004016107e29493929190611efb565b60806040518083038185885af1158015610800573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906108259190612021565b50600386868381811061083a5761083a611b57565b905060200281019061084c9190611d1b565b61085a906020810190611b85565b600781111561086b5761086b611b41565b14806108b95750600486868381811061088657610886611b57565b90506020028101906108989190611d1b565b6108a6906020810190611b85565b60078111156108b7576108b7611b41565b145b1561095b576003546001600160a01b03166397da0ceb8787848181106108e1576108e1611b57565b90506020028101906108f39190611d1b565b6040516001600160e01b031960e084901b16815261091691903390600401612098565b6020604051808303816000875af1158015610935573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061095991906120be565b505b8061096581611bd7565b91505061075a565b506040805160a0810182526000606082018181526080830182905282526020820181905291810182905290805b84811015610c1b5760028686838181106109b6576109b6611b57565b6109cc9260206080909202019081019150611b85565b60078111156109dd576109dd611b41565b03610b94578585828181106109f4576109f4611b57565b610a0a9260206080909202019081019150611b85565b8351906007811115610a1e57610a1e611b41565b90816007811115610a3157610a31611b41565b905250858582818110610a4657610a46611b57565b610a5f92604060809092020190810191506020016116dc565b83516001600160a01b03909116602090910152858582818110610a8457610a84611b57565b905060800201604001358360200181815250508351868683818110610aab57610aab611b57565b90506080020160600135610abf9190611bb8565b60408085019190915260035490516397da0ceb60e01b81526000916001600160a01b0316906397da0ceb90610afa90879033906004016120d7565b6020604051808303816000875af1158015610b19573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b3d91906120be565b905083604001518114610b925760405162461bcd60e51b815260206004820181905260248201527f436865636b207472616e7366657220455243323020616d6f756e74206661696c60448201526064016103bf565b505b6001868683818110610ba857610ba8611b57565b610bbe9260206080909202019081019150611b85565b6007811115610bcf57610bcf611b41565b03610c09578351868683818110610be857610be8611b57565b90506080020160600135610bfc9190611bb8565b610c069083612127565b91505b80610c1381611bd7565b91505061099a565b503481146106275760405162461bcd60e51b815260206004820152601a60248201527f4e617469766520616d6f756e7420636865636b206661696c656400000000000060448201526064016103bf565b6060610c75610d1b565b610c7f8383611152565b9392505050565b610c8e610d1b565b6001600160a01b038116610cf35760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016103bf565b61071681611102565b6000610d06610d1b565b610d12858585856111cc565b95945050505050565b6000546001600160a01b0316331461072b5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016103bf565b6002546040516278451d60e81b81526000916001600160a01b0316906378451d0090610da590859060040161213a565b6020604051808303816000875af1158015610dc4573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061033591906120be565b60025460405163496d511d60e11b81526001600160a01b03838116600483015230602483015260009283929116906392daa23a906044016040805180830381865afa158015610e3b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e5f91906121f0565b9094909350915050565b60025460405163650aac6160e01b815260048101879052602481018690526001600160a01b0385811660448301526064820185905261ffff841660848301529091169063650aac619060a401600060405180830381600087803b158015610ecf57600080fd5b505af1158015610624573d6000803e3d6000fd5b600254604051632e5f2cf160e01b81526001600160a01b0383811660048301526000921690632e5f2cf1906024016020604051808303816000875af1158015610f30573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103359190611cfe565b6040516001600160a01b0380851660248301528316604482015260648101829052610fbf9085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915261125d565b50505050565b604051636eb1769f60e11b81523060048201526001600160a01b038381166024830152600091839186169063dd62ed3e90604401602060405180830381865afa158015611016573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061103a91906120be565b6110449190612127565b6040516001600160a01b038516602482015260448101829052909150610fbf90859063095ea7b360e01b90606401610f88565b600254604051631f16aef360e01b81526004810188905260248101879052604481018690526064810185905283151560848201526001600160a01b0383811660a483015290911690631f16aef39060c401600060405180830381600087803b1580156110e257600080fd5b505af11580156110f6573d6000803e3d6000fd5b50505050505050505050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60025460405163a3fafd0560e01b81526060916001600160a01b03169063a3fafd0590611185908690869060040161222a565b6000604051808303816000875af11580156111a4573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610c7f919081019061224e565b600254604051639aab948160e01b8152600481018690526001600160a01b0385811660248301526044820185905261ffff841660648301526000921690639aab9481906084016020604051808303816000875af1158015611231573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d1291906120be565b949350505050565b60006112b2826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166113349092919063ffffffff16565b80519091501561132f57808060200190518101906112d09190611cfe565b61132f5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016103bf565b505050565b6060611255848460008585600080866001600160a01b0316858760405161135b91906122f7565b60006040518083038185875af1925050503d8060008114611398576040519150601f19603f3d011682016040523d82523d6000602084013e61139d565b606091505b50915091506113ae878383876113b9565b979650505050505050565b60608315611428578251600003611421576001600160a01b0385163b6114215760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016103bf565b5081611255565b611255838381511561143d5781518083602001fd5b8060405162461bcd60e51b81526004016103bf9190612309565b634e487b7160e01b600052604160045260246000fd5b604051606081016001600160401b038111828210171561148f5761148f611457565b60405290565b604080519081016001600160401b038111828210171561148f5761148f611457565b60405160a081016001600160401b038111828210171561148f5761148f611457565b604051601f8201601f191681016001600160401b038111828210171561150157611501611457565b604052919050565b801515811461071657600080fd5b6001600160a01b038116811461071657600080fd5b60006001600160401b0382111561154557611545611457565b5060051b60200190565b803561ffff8116811461156157600080fd5b919050565b600082601f83011261157757600080fd5b8135602061158c6115878361152c565b6114d9565b828152606092830285018201928282019190878511156115ab57600080fd5b8387015b858110156116025781818a0312156115c75760008081fd5b6115cf61146d565b81356115da81611517565b8152818601358682015260406115f181840161154f565b9082015284529284019281016115af565b5090979650505050505050565b60006020828403121561162157600080fd5b81356001600160401b038082111561163857600080fd5b9083019081850360c081121561164d57600080fd5b611655611495565b60a082121561166357600080fd5b61166b6114b7565b9150833582526020840135602083015260408401356040830152606084013561169381611509565b606083015260808401356116a681611517565b608083015290815260a083013590828211156116c157600080fd5b6116cd87838601611566565b60208201529695505050505050565b6000602082840312156116ee57600080fd5b8135610c7f81611517565b600080600080600060a0868803121561171157600080fd5b8535945060208601359350604086013561172a81611517565b92506060860135915061173f6080870161154f565b90509295509295909350565b60008083601f84011261175d57600080fd5b5081356001600160401b0381111561177457600080fd5b6020830191508360208260051b850101111561178f57600080fd5b9250929050565b60008083601f8401126117a857600080fd5b5081356001600160401b038111156117bf57600080fd5b6020830191508360208260071b850101111561178f57600080fd5b600080600080600080606087890312156117f357600080fd5b86356001600160401b038082111561180a57600080fd5b6118168a838b0161174b565b9098509650602089013591508082111561182f57600080fd5b61183b8a838b0161174b565b9096509450604089013591508082111561185457600080fd5b5061186189828a01611796565b979a9699509497509295939492505050565b60008060008060008060c0878903121561188c57600080fd5b8635955060208701359450604087013593506060870135925060808701356118b381611509565b915060a08701356118c381611517565b809150509295509295509295565b6000806000806000606086880312156118e957600080fd5b85356001600160401b038082111561190057600080fd5b61190c89838a0161174b565b909750955060209150878201358181111561192657600080fd5b6119328a828b01611796565b90965094505060408801358181111561194a57600080fd5b88019050601f8101891361195d57600080fd5b803561196b6115878261152c565b81815260059190911b8201830190838101908b83111561198a57600080fd5b928401925b828410156119b15783356119a281611517565b8252928401929084019061198f565b80955050505050509295509295909350565b600080604083850312156119d657600080fd5b82356119e181611517565b91506020838101356001600160401b038111156119fd57600080fd5b8401601f81018613611a0e57600080fd5b8035611a1c6115878261152c565b81815260059190911b82018301908381019088831115611a3b57600080fd5b928401925b82841015611a5957833582529284019290840190611a40565b80955050505050509250929050565b600081518084526020808501945080840160005b83811015611a9857815187529582019590820190600101611a7c565b509495945050505050565b602081526000610c7f6020830184611a68565b60008060008060808587031215611acc57600080fd5b843593506020850135611ade81611517565b925060408501359150611af36060860161154f565b905092959194509250565b60208082526023908201527f417272617920706172616d73206d757374206861766520657175616c206c656e6040820152620cee8d60eb1b606082015260800190565b634e487b7160e01b600052602160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b6008811061071657600080fd5b803561156181611b6d565b600060208284031215611b9757600080fd5b8135610c7f81611b6d565b634e487b7160e01b600052601160045260246000fd5b6000816000190483118215151615611bd257611bd2611ba2565b500290565b600060018201611be957611be9611ba2565b5060010190565b600082611c0d57634e487b7160e01b600052601260045260246000fd5b500490565b60088110611c3057634e487b7160e01b600052602160045260246000fd5b9052565b8035611c3f81611b6d565b611c498382611c12565b506020810135611c5881611517565b6001600160a01b0316602083015260408181013590830152606090810135910152565b81835260208301925060008160005b84811015611caf57611c9c8683611c34565b6080958601959190910190600101611c8a565b5093949350505050565b60018060a01b0385168152836020820152606060408201526000611ce1606083018486611c7b565b9695505050505050565b8181038181111561033557610335611ba2565b600060208284031215611d1057600080fd5b8151610c7f81611509565b6000823561015e19833603018112611d3257600080fd5b9190910192915050565b6000808335601e19843603018112611d5357600080fd5b83016020810192503590506001600160401b03811115611d7257600080fd5b60608102360382131561178f57600080fd5b80356001600160f81b03198116811461156157600080fd5b8183526000602080850194508260005b85811015611a98576001600160f81b0319611dc683611d84565b1687528282013583880152604080830135611de081611517565b6001600160a01b0316908801526060968701969190910190600101611dac565b6000808335601e19843603018112611e1757600080fd5b83016020810192503590506001600160401b03811115611e3657600080fd5b8060061b360382131561178f57600080fd5b8183526000602080850194508260005b85811015611a98576001600160f81b0319611e7283611d84565b168752818301358388015260409687019690910190600101611e58565b8183526000602080850194508260005b85811015611a98578135611eb281611517565b6001600160a01b0316875261ffff611ecb83850161154f565b16878401526040968701969190910190600101611e9f565b80356001600160f01b03198116811461156157600080fd5b60608152611f0c6060820186611c34565b60006080860135611f1c81611517565b6001600160a01b031660e0830152611f3760a0870187611d3c565b6101606101008181870152611f516101c087018486611d9c565b9350611f6060c08b018b611e00565b9350605f196101208189880301818a0152611f7c878785611e48565b9650611f8b60e08e018e611e00565b96509250610140828a890301818b0152611fa6888886611e8f565b9750611fb3858f01611b7a565b9650611fc1868b0188611c12565b818e01356101808b0152611fd6818f01611ee3565b9650505050505050611ff56101a08501826001600160f01b0319169052565b508281036020840152612009818688611c7b565b915050610d1260408301846001600160a01b03169052565b6000818303608081121561203457600080fd5b61203c61146d565b604082121561204a57600080fd5b612052611495565b9150835161205f81611b6d565b8252602084015161206f81611517565b806020840152508181526040840151602082015260608401516040820152809250505092915050565b60a081016120a68285611c34565b6001600160a01b039290921660809190910152919050565b6000602082840312156120d057600080fd5b5051919050565b600060a08201905083516120ec838251611c12565b6020908101516001600160a01b0390811684830152908501516040808501919091529094015160608301529190921660809092019190915290565b8082018082111561033557610335611ba2565b602080825282518051838301528082015160408085019190915280820151606080860191909152808301511515608080870191909152909201516001600160a01b0390811660a08601528584015160c080870152805160e08701819052600095949185019386939290916101008901905b808610156121e2578651805186168352888101518984015284015161ffff16848301529587019560019590950194908201906121ab565b509998505050505050505050565b6000806040838503121561220357600080fd5b825161220e81611509565b602084015190925061221f81611509565b809150509250929050565b6001600160a01b038316815260406020820181905260009061125590830184611a68565b6000602080838503121561226157600080fd5b82516001600160401b0381111561227757600080fd5b8301601f8101851361228857600080fd5b80516122966115878261152c565b81815260059190911b820183019083810190878311156122b557600080fd5b928401925b828410156113ae578351825292840192908401906122ba565b60005b838110156122ee5781810151838201526020016122d6565b50506000910152565b60008251611d328184602087016122d3565b60208152600082518060208401526123288160408501602087016122d3565b601f01601f1916919091016040019291505056fea264697066735822122028f37411c95aa3e50ccd1ef8884ea49135d2f2e71b406d69887d3f24b9fbb01a64736f6c63430008100033

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

000000000000000000000000825f886d9116170ba5e8e70132ba72d883c079fe

-----Decoded View---------------
Arg [0] : _subscrRegistry (address): 0x825f886D9116170ba5E8E70132ba72d883C079FE

-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 000000000000000000000000825f886d9116170ba5e8e70132ba72d883c079fe


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

Txn Hash Block Value Eth2 PubKey Valid
View All Deposits
[ Download: CSV Export  ]
[ 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.