Contract 0x4898D1e6d9761B4215901817FBe9F12750238882 8

Txn Hash Method
Block
From
To
Value [Txn Fee]
0x9ca87aa722db970ff86ed1dce6d0123faecc29e5a0b7eb77b627a23c9e91a3c30x60806040165940532022-12-10 2:11:37299 days 57 mins ago0x54812dbab593674cd4f1216264895be48b55c5e3 IN  Create: CaskSubscriptionManager0 CELO0.001371416
[ Download CSV Export 
Parent Txn Hash Block From To Value
Index Block
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
CaskSubscriptionManager

Compiler Version
v0.8.9+commit.e5eed63a

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
File 1 of 20 : CaskSubscriptionManager.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import "@chainlink/contracts/src/v0.8/interfaces/KeeperCompatibleInterface.sol";

import "../interfaces/ICaskSubscriptionManager.sol";
import "../interfaces/ICaskSubscriptionPlans.sol";
import "../interfaces/ICaskSubscriptions.sol";
import "../interfaces/ICaskVault.sol";

contract CaskSubscriptionManager is
ICaskSubscriptionManager,
Initializable,
OwnableUpgradeable,
PausableUpgradeable,
KeeperCompatibleInterface
{

    /************************** PARAMETERS **************************/

    /** @dev contract to manage subscription plan definitions. */
    ICaskSubscriptionPlans public subscriptionPlans;
    ICaskSubscriptions public subscriptions;

    /** @dev vault to use for payments. */
    ICaskVault public vault;

    /** @dev minimum total fee to charge, if rate fees do not add up to this amount */
    uint256 public paymentFeeMin;

    /** @dev min and max percentage to charge on payments, in bps. 50% = 5000. */
    uint256 public paymentFeeRateMin; // floor if full discount applied
    uint256 public paymentFeeRateMax; // fee if no discount applied

    /** @dev factor used to reduce payment fee based on qty of staked CASK */
    uint256 public stakeTargetFactor;

    /** @dev size (in seconds) of buckets to group subscriptions into for processing */
    uint32 public processBucketSize;

    /** @dev map used to track when subscriptions need attention next */
    mapping(CheckType => mapping(uint32 => uint256[])) private processQueue; // renewal bucket => subscriptionId[]
    mapping(CheckType => uint32) private processingBucket; // current bucket being processed

    /** @dev min value for a payment. */
    uint256 public paymentMinValue;

    /** @dev max age a process bucket can grow to before a forced processing occurs. */
    uint32 public processBucketMaxAge;

    /** @dev number of seconds between failed payment retries. */
    uint32 public paymentRetryDelay;

    modifier onlySubscriptions() {
        require(_msgSender() == address(subscriptions), "!AUTH");
        _;
    }

    function initialize(
        address _vault,
        address _subscriptionPlans,
        address _subscriptions
    ) public initializer {
        __Ownable_init();
        __Pausable_init();

        subscriptionPlans = ICaskSubscriptionPlans(_subscriptionPlans);
        subscriptions = ICaskSubscriptions(_subscriptions);
        vault = ICaskVault(_vault);

        // parameter defaults
        paymentMinValue = 0;
        paymentFeeMin = 0;
        paymentFeeRateMin = 0;
        paymentFeeRateMax = 0;
        stakeTargetFactor = 0;
        processBucketSize = 300;
        processBucketMaxAge = 1 hours;
        paymentRetryDelay = 12 hours;

        processingBucket[CheckType.Active] = _currentBucket();
        processingBucket[CheckType.PastDue] = _currentBucket();
    }
    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor() initializer {}

    function _parsePlanData(
        bytes32 _planData
    ) internal pure returns(ICaskSubscriptions.PlanInfo memory) {
        bytes1 options = bytes1(_planData << 248);
        return ICaskSubscriptions.PlanInfo({
        price: uint256(_planData >> 160),
        planId: uint32(bytes4(_planData << 96)),
        period: uint32(bytes4(_planData << 128)),
        freeTrial: uint32(bytes4(_planData << 160)),
        maxActive: uint32(bytes4(_planData << 192)),
        minPeriods: uint16(bytes2(_planData << 224)),
        gracePeriod: uint8(bytes1(_planData << 240)),
        canPause: options & 0x01 == 0x01,
        canTransfer: options & 0x02 == 0x02
        });
    }

    function _planDataPrice(
        bytes32 _planData
    ) internal pure returns(uint256) {
        return uint256(_planData >> 160);
    }

    function _parseNetworkData(
        bytes32 _networkData
    ) internal pure returns(ICaskSubscriptions.NetworkInfo memory) {
        return ICaskSubscriptions.NetworkInfo({
            network: address(bytes20(_networkData)),
            feeBps: uint16(bytes2(_networkData << 160))
        });
    }

    function _parseDiscountData(
        bytes32 _discountData
    ) internal pure returns(ICaskSubscriptionPlans.Discount memory) {
        bytes1 options = bytes1(_discountData << 240);
        return ICaskSubscriptionPlans.Discount({
            value: uint256(_discountData >> 160),
            validAfter: uint32(bytes4(_discountData << 96)),
            expiresAt: uint32(bytes4(_discountData << 128)),
            maxRedemptions: uint32(bytes4(_discountData << 160)),
            planId: uint32(bytes4(_discountData << 192)),
            applyPeriods: uint16(bytes2(_discountData << 224)),
            discountType: ICaskSubscriptionPlans.DiscountType(uint8(bytes1(_discountData << 248))),
            isFixed: options & 0x01 == 0x01
        });
    }

    function processSinglePayment(
        address _consumer,
        address _provider,
        uint256 _subscriptionId,
        uint256 _value
    ) external onlySubscriptions returns(bool) {
        return _processPayment(_consumer, _provider, _subscriptionId, _value);
    }

    function _processPayment(
        address _consumer,
        address _provider,
        uint256 _subscriptionId,
        uint256 _value
    ) internal returns(bool) {
        (ICaskSubscriptions.Subscription memory subscription,) = subscriptions.getSubscription(_subscriptionId);

        uint256 paymentFeeRateAdjusted = paymentFeeRateMax;

        if (stakeTargetFactor > 0) {
            // TODO: reduce fee based on staked balance
            //        uint256 stakedBalance = ICaskStakeManager(stakeManager).providerStakeBalanceOf(_provider);
            uint256 stakedBalance = 0;

            ICaskSubscriptions.PlanInfo memory planData = _parsePlanData(subscription.planData);

            if (stakedBalance > 0 && planData.period > 0) {
                uint256 loadFactor = 365 / (planData.period / 1 days);
                uint256 noFeeTarget = subscriptions.getProviderSubscriptionCount(subscription.provider, false, 0) *
                stakeTargetFactor * loadFactor;

                paymentFeeRateAdjusted = paymentFeeRateMax - (paymentFeeRateMax * (stakedBalance / noFeeTarget));
                if (paymentFeeRateAdjusted < paymentFeeRateMin) {
                    paymentFeeRateAdjusted = paymentFeeRateMin;
                }
            }
        }

        ICaskSubscriptionPlans.Provider memory providerProfile = subscriptionPlans.getProviderProfile(_provider);

        address paymentAddress = _provider;
        if (providerProfile.paymentAddress != address(0)) {
            paymentAddress = providerProfile.paymentAddress;
        }

        return _sendPayment(subscription, _consumer, paymentAddress, _value, paymentFeeRateAdjusted);
    }

    function _sendPayment(
        ICaskSubscriptions.Subscription memory _subscription,
        address _consumer,
        address _paymentAddress,
        uint256 _value,
        uint256 _protocolFeeBps
    ) internal returns(bool) {
        uint256 protocolFee = _value * _protocolFeeBps / 10000;
        if (protocolFee < paymentFeeMin) {
            protocolFee = paymentFeeMin;
        }

        if (_subscription.networkData > 0) {
            ICaskSubscriptions.NetworkInfo memory networkData = _parseNetworkData(_subscription.networkData);
            uint256 networkFee = _value * networkData.feeBps / 10000;
            require(_value > protocolFee + networkFee, "!VALUE_TOO_LOW");
            try vault.protocolPayment(_consumer, _paymentAddress, _value, protocolFee, networkData.network, networkFee) {
                return true;
            } catch {
                return false;
            }
        } else {
            require(_value > protocolFee, "!VALUE_TOO_LOW");
            try vault.protocolPayment(_consumer, _paymentAddress, _value, protocolFee) {
                return true;
            } catch {
                return false;
            }
        }
    }

    function _bucketAt(
        uint32 _timestamp
    ) internal view returns(uint32) {
        return _timestamp - (_timestamp % processBucketSize) + processBucketSize;
    }

    function _currentBucket() internal view returns(uint32) {
        uint32 timestamp = uint32(block.timestamp);
        return timestamp - (timestamp % processBucketSize);
    }

    function queueItem(
        CheckType _checkType,
        uint32 _bucket,
        uint256 _idx
    ) external view returns(uint256) {
        return processQueue[_checkType][_bucket][_idx];
    }

    function queueSize(
        CheckType _checkType,
        uint32 _bucket
    ) external view returns(uint256) {
        return processQueue[_checkType][_bucket].length;
    }

    function queuePosition(
        CheckType _checkType
    ) external view returns(uint32) {
        return processingBucket[_checkType];
    }

    function checkUpkeep(
        bytes calldata checkData
    ) external view override returns(bool upkeepNeeded, bytes memory performData) {
        (
        uint256 limit,
        uint256 minDepth,
        CheckType checkType
        ) = abi.decode(checkData, (uint256, uint256, CheckType));

        uint32 currentBucket = _currentBucket();
        upkeepNeeded = false;

        uint32 checkBucket = processingBucket[checkType];
        if (checkBucket == 0) {
            checkBucket = currentBucket;
        }

        // if queue is more than an hour old, all hands on deck
        if (currentBucket >= checkBucket && currentBucket - checkBucket > processBucketMaxAge) {
            upkeepNeeded = true;
        } else {
            while (checkBucket <= currentBucket) {
                if (processQueue[checkType][checkBucket].length > 0 &&
                    processQueue[checkType][checkBucket].length >= minDepth)
                {
                    upkeepNeeded = true;
                    break;
                }
                checkBucket += processBucketSize;
            }
        }

        performData = abi.encode(limit, processQueue[checkType][checkBucket].length, checkType);
    }


    function performUpkeep(
        bytes calldata performData
    ) external override whenNotPaused {
        (
        uint256 limit,
        uint256 depth,
        CheckType checkType
        ) = abi.decode(performData, (uint256, uint256, CheckType));

        uint32 currentBucket = _currentBucket();
        uint256 renewals = 0;
        uint256 maxBucketChecks = limit * 5;

        if (processingBucket[checkType] == 0) {
            processingBucket[checkType] = currentBucket;
        }

        while (renewals < limit && maxBucketChecks > 0 && processingBucket[checkType] <= currentBucket) {
            uint256 queueLen = processQueue[checkType][processingBucket[checkType]].length;
            if (queueLen > 0) {
                uint256 subscriptionId = processQueue[checkType][processingBucket[checkType]][queueLen-1];
                processQueue[checkType][processingBucket[checkType]].pop();
                _renewSubscription(subscriptionId);
                renewals += 1;
            } else {
                if (processingBucket[checkType] < currentBucket) {
                    processingBucket[checkType] += processBucketSize;
                    maxBucketChecks -= 1;
                } else {
                    break; // nothing left to do
                }
            }
        }

        emit SubscriptionManagerReport(limit, renewals, depth, checkType,
            processQueue[checkType][processingBucket[checkType]].length, processingBucket[checkType]);
    }

    function renewSubscription(
        uint256 _subscriptionId
    ) external override whenNotPaused {
        _renewSubscription(_subscriptionId);
    }

    function _renewSubscription(
        uint256 _subscriptionId
    ) internal {
        (
        ICaskSubscriptions.Subscription memory subscription,
        address consumer
        ) = subscriptions.getSubscription(_subscriptionId);

        uint32 timestamp = uint32(block.timestamp);

        // paused subscriptions will be re-queued when resumed
        if (subscription.status == ICaskSubscriptions.SubscriptionStatus.Paused ||
            subscription.status == ICaskSubscriptions.SubscriptionStatus.Canceled ||
            subscription.status == ICaskSubscriptions.SubscriptionStatus.None)
        {
            return;
        }

        // not time to renew yet, re-queue for renewal time
        if (subscription.renewAt > timestamp) {
            processQueue[CheckType.Active][_bucketAt(subscription.renewAt)].push(_subscriptionId);
            return;
        }

        // paused subscription is time for renewal - change to Paused status
        if (subscription.status == ICaskSubscriptions.SubscriptionStatus.PendingPause) {
            subscriptions.managerCommand(_subscriptionId, ICaskSubscriptions.ManagerCommand.Pause);
            return;
        }

        // subscription scheduled to be canceled by consumer or has hit its cancelAt time
        if ((subscription.cancelAt > 0 && subscription.cancelAt <= timestamp) ||
            (subscriptionPlans.getPlanStatus(subscription.provider, subscription.planId) ==
                ICaskSubscriptionPlans.PlanStatus.EndOfLife &&
                subscriptionPlans.getPlanEOL(subscription.provider, subscription.planId) <= timestamp))
        {
            subscriptions.managerCommand(_subscriptionId, ICaskSubscriptions.ManagerCommand.Cancel);
            return;
        }

        // if a plan change is pending, switch to use new plan info
        if (subscriptions.getPendingPlanChange(_subscriptionId) > 0) {
            subscriptions.managerCommand(_subscriptionId, ICaskSubscriptions.ManagerCommand.PlanChange);
            (subscription,) = subscriptions.getSubscription(_subscriptionId); // refresh
        }

        ICaskSubscriptions.PlanInfo memory planInfo = _parsePlanData(subscription.planData);
        uint256 chargePrice = planInfo.price;

        if (planInfo.price == 0) {
            // free plan, skip. will be re-queued when they upgrade to a paid plan
            return;
        }

        // maybe apply discount
        if (subscription.discountId > 0) {
            ICaskSubscriptionPlans.Discount memory discountInfo = _parseDiscountData(subscription.discountData);

            if(discountInfo.applyPeriods == 0 ||
                subscription.createdAt + (planInfo.period * discountInfo.applyPeriods) > timestamp)
            {
                if (_discountCurrentlyApplies(consumer, subscription.discountId, discountInfo)) {
                    uint256 discountValue = discountInfo.isFixed ?
                        discountInfo.value :
                        chargePrice * discountInfo.value / 10000;
                    chargePrice = chargePrice > discountValue ? chargePrice - discountValue : 0;
                }
            } else {
                subscriptions.managerCommand(_subscriptionId, ICaskSubscriptions.ManagerCommand.ClearDiscount);
            }
        }

        if (chargePrice < paymentMinValue || chargePrice <= paymentFeeMin) {
            subscriptions.managerCommand(_subscriptionId, ICaskSubscriptions.ManagerCommand.Cancel);

        } else {

            if (_processPayment(consumer, subscription.provider, _subscriptionId, chargePrice)) {

                if (subscription.renewAt + planInfo.period < timestamp) {
                    // subscription is still behind, put in next queue bucket
                    processQueue[CheckType.PastDue][_bucketAt(timestamp)].push(_subscriptionId);
                } else {
                    processQueue[CheckType.Active][_bucketAt(subscription.renewAt + planInfo.period)].push(_subscriptionId);
                }

                subscriptions.managerCommand(_subscriptionId, ICaskSubscriptions.ManagerCommand.Renew);

            } else {

                if (subscription.renewAt < timestamp - (planInfo.gracePeriod * 1 days)) {
                    subscriptions.managerCommand(_subscriptionId, ICaskSubscriptions.ManagerCommand.Cancel);
                } else if (subscription.status != ICaskSubscriptions.SubscriptionStatus.PastDue) {
                    processQueue[CheckType.PastDue][_bucketAt(timestamp + paymentRetryDelay)].push(_subscriptionId);
                    subscriptions.managerCommand(_subscriptionId, ICaskSubscriptions.ManagerCommand.PastDue);
                } else {
                    processQueue[CheckType.PastDue][_bucketAt(timestamp + paymentRetryDelay)].push(_subscriptionId);
                }

            }
        }
    }

    function _discountCurrentlyApplies(
        address _consumer,
        bytes32 _discountValidator,
        ICaskSubscriptionPlans.Discount memory _discountInfo
    ) internal returns(bool) {
        if (_discountInfo.discountType == ICaskSubscriptionPlans.DiscountType.Code) {
            return true;
        } else if (_discountInfo.discountType == ICaskSubscriptionPlans.DiscountType.ERC20) {
            return subscriptionPlans.erc20DiscountCurrentlyApplies(_consumer, _discountValidator);
        }
        return false;
    }


    /************************** ADMIN FUNCTIONS **************************/

    function pause() external onlyOwner {
        _pause();
    }

    function unpause() external onlyOwner {
        _unpause();
    }

    function setParameters(
        uint256 _paymentMinValue,
        uint256 _paymentFeeMin,
        uint256 _paymentFeeRateMin,
        uint256 _paymentFeeRateMax,
        uint256 _stakeTargetFactor,
        uint32 _processBucketSize,
        uint32 _processBucketMaxAge,
        uint32 _paymentRetryDelay
    ) external onlyOwner {
        require(_paymentFeeRateMin < 10000, "!INVALID(paymentFeeRateMin)");
        require(_paymentFeeRateMax < 10000, "!INVALID(paymentFeeRateMax)");

        paymentMinValue = _paymentMinValue;
        paymentFeeMin = _paymentFeeMin;
        paymentFeeRateMin = _paymentFeeRateMin;
        paymentFeeRateMax = _paymentFeeRateMax;
        stakeTargetFactor = _stakeTargetFactor;
        processBucketSize = _processBucketSize;
        processBucketMaxAge = _processBucketMaxAge;
        paymentRetryDelay = _paymentRetryDelay;

        // re-map to new bucket size
        processingBucket[CheckType.Active] = _bucketAt(processingBucket[CheckType.Active]);
        processingBucket[CheckType.PastDue] = _bucketAt(processingBucket[CheckType.PastDue]);

        emit SetParameters();
    }

    function setProcessingBucket(
        CheckType _checkType,
        uint32 _timestamp
    ) external onlyOwner {
        processingBucket[_checkType] = _bucketAt(_timestamp);
    }

}

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

pragma solidity ^0.8.0;

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

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

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

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

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

        _;

        if (isTopLevelCall) {
            _initializing = false;
        }
    }

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

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

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.0;

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

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

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

    bool private _paused;

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

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

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

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

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

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

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

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

interface KeeperCompatibleInterface {
  /**
   * @notice method that is simulated by the keepers to see if any work actually
   * needs to be performed. This method does does not actually need to be
   * executable, and since it is only ever simulated it can consume lots of gas.
   * @dev To ensure that it is never called, you may want to add the
   * cannotExecute modifier from KeeperBase to your implementation of this
   * method.
   * @param checkData specified in the upkeep registration so it is always the
   * same for a registered upkeep. This can easilly be broken down into specific
   * arguments using `abi.decode`, so multiple upkeeps can be registered on the
   * same contract and easily differentiated by the contract.
   * @return upkeepNeeded boolean to indicate whether the keeper should call
   * performUpkeep or not.
   * @return performData bytes that the keeper should call performUpkeep with, if
   * upkeep is needed. If you would like to encode data to decode later, try
   * `abi.encode`.
   */
  function checkUpkeep(bytes calldata checkData) external returns (bool upkeepNeeded, bytes memory performData);

  /**
   * @notice method that is actually executed by the keepers, via the registry.
   * The data returned by the checkUpkeep simulation will be passed into
   * this method to actually be executed.
   * @dev The input to this method should not be trusted, and the caller of the
   * method should not even be restricted to any single registry. Anyone should
   * be able call it, and the input should be validated, there is no guarantee
   * that the data passed in is the performData returned from checkUpkeep. This
   * could happen due to malicious keepers, racing keepers, or simply a state
   * change while the performUpkeep transaction is waiting for confirmation.
   * Always validate the data passed in.
   * @param performData is the data which was passed back from the checkData
   * simulation. If it is encoded, it can easily be decoded into other types by
   * calling `abi.decode`. This data should not be trusted, and should be
   * validated against the contract's current state.
   */
  function performUpkeep(bytes calldata performData) external;
}

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

interface ICaskSubscriptionManager {

    enum CheckType {
        None,
        Active,
        PastDue
    }

    function queueItem(CheckType _checkType, uint32 _bucket, uint256 _idx) external view returns(uint256);

    function queueSize(CheckType _checkType, uint32 _bucket) external view returns(uint256);

    function queuePosition(CheckType _checkType) external view returns(uint32);

    function processSinglePayment(address _consumer, address _provider,
        uint256 _subscriptionId, uint256 _value) external returns(bool);

    function renewSubscription(uint256 _subscriptionId) external;

    /** @dev Emitted when the keeper job performs renewals. */
    event SubscriptionManagerReport(uint256 limit, uint256 renewals, uint256 depth, CheckType checkType,
        uint256 queueRemaining, uint32 currentBucket);

    /** @dev Emitted when manager parameters are changed. */
    event SetParameters();
}

File 7 of 20 : ICaskSubscriptionPlans.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface ICaskSubscriptionPlans {

    enum PlanStatus {
        Enabled,
        Disabled,
        EndOfLife
    }

    enum DiscountType {
        None,
        Code,
        ERC20
    }

    struct Discount {
        uint256 value;
        uint32 validAfter;
        uint32 expiresAt;
        uint32 maxRedemptions;
        uint32 planId;
        uint16 applyPeriods;
        DiscountType discountType;
        bool isFixed;
    }

    struct Provider {
        address paymentAddress;
        uint256 nonce;
        string cid;
    }

    function setProviderProfile(address _paymentAddress, string calldata _cid, uint256 _nonce) external;

    function getProviderProfile(address _provider) external view returns(Provider memory);

    function getPlanStatus(address _provider, uint32 _planId) external view returns (PlanStatus);

    function getPlanEOL(address _provider, uint32 _planId) external view returns (uint32);

    function disablePlan(uint32 _planId) external;

    function enablePlan(uint32 _planId) external;

    function retirePlan(uint32 _planId, uint32 _retireAt) external;

    function verifyPlan(bytes32 _planData, bytes32 _merkleRoot,
        bytes32[] calldata _merkleProof) external view returns(bool);

    function getDiscountRedemptions(address _provider, uint32 _planId,
        bytes32 _discountId) external view returns(uint256);

    function verifyAndConsumeDiscount(address _consumer, address _provider, uint32 _planId,
        bytes32[] calldata _discountProof) external returns(bytes32);

    function verifyDiscount(address _consumer, address _provider, uint32 _planId,
        bytes32[] calldata _discountProof) external returns(bytes32);

    function erc20DiscountCurrentlyApplies(address _consumer, bytes32 _discountValidator) external returns(bool);

    function verifyProviderSignature(address _provider, uint256 _nonce, bytes32 _planMerkleRoot,
        bytes32 _discountMerkleRoot, bytes memory _providerSignature) external view returns (bool);

    function verifyNetworkData(address _network, bytes32 _networkData,
        bytes memory _networkSignature) external view returns (bool);


    /** @dev Emitted when `provider` sets their profile info */
    event ProviderSetProfile(address indexed provider, address indexed paymentAddress, uint256 nonce, string cid);

    /** @dev Emitted when `provider` disables a subscription plan */
    event PlanDisabled(address indexed provider, uint32 indexed planId);

    /** @dev Emitted when `provider` enables a subscription plan */
    event PlanEnabled(address indexed provider, uint32 indexed planId);

    /** @dev Emitted when `provider` end-of-lifes a subscription plan */
    event PlanRetired(address indexed provider, uint32 indexed planId, uint32 retireAt);

}

File 8 of 20 : ICaskSubscriptions.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol";
import "./ICaskSubscriptionManager.sol";

interface ICaskSubscriptions is IERC721Upgradeable {

    enum SubscriptionStatus {
        None,
        Trialing,
        Active,
        Paused,
        Canceled,
        PastDue,
        PendingPause
    }

    enum ManagerCommand {
        None,
        PlanChange,
        Cancel,
        PastDue,
        Renew,
        ClearDiscount,
        Pause
    }

    struct Subscription {
        bytes32 planData;
        bytes32 networkData;
        bytes32 discountId;
        bytes32 discountData;
        bytes32 ref;
        address provider;
        SubscriptionStatus status;
        uint32 planId;
        uint32 createdAt;
        uint32 renewAt;
        uint32 minTermAt;
        uint32 cancelAt;
        string cid;
        string dataCid;
    }

    struct PlanInfo {
        uint256 price;
        uint32 planId;
        uint32 period;
        uint32 freeTrial;
        uint32 maxActive;
        uint16 minPeriods;
        uint8 gracePeriod;
        bool canPause;
        bool canTransfer;
    }

    struct NetworkInfo {
        address network;
        uint16 feeBps;
    }

    /************************** SUBSCRIPTION INSTANCE METHODS **************************/

    function createSubscription(
        uint256 _nonce,
        bytes32[] calldata _planProof,
        bytes32[] calldata _discountProof,
        uint32 _cancelAt,
        bytes memory _providerSignature,
        string calldata _cid
    ) external;

    function createNetworkSubscription(
        uint256 _nonce,
        bytes32[] calldata _planProof,
        bytes32[] calldata _discountProof,
        bytes32 _networkData,
        uint32 _cancelAt,
        bytes memory _providerSignature,
        bytes memory _networkSignature,
        string calldata _cid
    ) external;

    function changeSubscriptionPlan(
        uint256 _subscriptionId,
        uint256 _nonce,
        bytes32[] calldata _planProof,
        bytes32[] calldata _discountProof,
        bytes memory _providerSignature,
        string calldata _cid
    ) external;

    function attachData(uint256 _subscriptionId, string calldata _dataCid) external;

    function pauseSubscription(uint256 _subscriptionId) external;

    function resumeSubscription(uint256 _subscriptionId) external;

    function cancelSubscription(uint256 _subscriptionId, uint32 _cancelAt) external;

    function managerCommand(uint256 _subscriptionId, ManagerCommand _command) external;

    function getSubscription(uint256 _subscriptionId) external view returns
        (Subscription memory subscription, address currentOwner);

    function getConsumerSubscription(address _consumer, uint256 _idx) external view returns(uint256);

    function getConsumerSubscriptionCount(address _consumer) external view returns (uint256);

    function getProviderSubscription(address _provider, uint256 _idx) external view returns(uint256);

    function getProviderSubscriptionCount(address _provider, bool _includeCanceled, uint32 _planId) external view returns (uint256);

    function getActiveSubscriptionCount(address _consumer, address _provider, uint32 _planId) external view returns(uint256);

    function getPendingPlanChange(uint256 _subscriptionId) external view returns (bytes32);


    /************************** SUBSCRIPTION EVENTS **************************/

    /** @dev Emitted when `consumer` subscribes to `provider` plan `planId` */
    event SubscriptionCreated(address indexed consumer, address indexed provider,
        uint256 indexed subscriptionId, bytes32 ref, uint32 planId, bytes32 discountId);

    /** @dev Emitted when `consumer` changes the plan to `provider` on subscription `subscriptionId` */
    event SubscriptionChangedPlan(address indexed consumer, address indexed provider,
        uint256 indexed subscriptionId, bytes32 ref, uint32 prevPlanId, uint32 planId, bytes32 discountId);

    /** @dev Emitted when `consumer` changes the plan to `provider` on subscription `subscriptionId` */
    event SubscriptionPendingChangePlan(address indexed consumer, address indexed provider,
        uint256 indexed subscriptionId, bytes32 ref, uint32 prevPlanId, uint32 planId);

    /** @dev Emitted when `consumer` initiates a pause of the subscription to `provider` on subscription `subscriptionId` */
    event SubscriptionPendingPause(address indexed consumer, address indexed provider,
        uint256 indexed subscriptionId, bytes32 ref, uint32 planId);

    /** @dev Emitted when a pending pause subscription attempts to renew but is paused */
    event SubscriptionPaused(address indexed consumer, address indexed provider,
        uint256 indexed subscriptionId, bytes32 ref, uint32 planId);

    /** @dev Emitted when `consumer` resumes the subscription to `provider` on subscription `subscriptionId` */
    event SubscriptionResumed(address indexed consumer, address indexed provider,
        uint256 indexed subscriptionId, bytes32 ref, uint32 planId);

    /** @dev Emitted when `consumer` unsubscribes to `provider` on subscription `subscriptionId` */
    event SubscriptionPendingCancel(address indexed consumer, address indexed provider,
        uint256 indexed subscriptionId, bytes32 ref, uint32 planId, uint32 cancelAt);

    /** @dev Emitted when `consumer` has canceled and the current period is over on subscription `subscriptionId` */
    event SubscriptionCanceled(address indexed consumer, address indexed provider,
        uint256 indexed subscriptionId, bytes32 ref, uint32 planId);

    /** @dev Emitted when `consumer` successfully renews to `provider` on subscription `subscriptionId` */
    event SubscriptionRenewed(address indexed consumer, address indexed provider,
        uint256 indexed subscriptionId, bytes32 ref, uint32 planId);

    /** @dev Emitted when `consumer` subscription trial ends and goes active to `provider`
     * on subscription `subscriptionId`
     */
    event SubscriptionTrialEnded(address indexed consumer, address indexed provider,
        uint256 indexed subscriptionId, bytes32 ref, uint32 planId);

    /** @dev Emitted when `consumer` renewal fails to `provider` on subscription `subscriptionId` */
    event SubscriptionPastDue(address indexed consumer, address indexed provider,
        uint256 indexed subscriptionId, bytes32 ref, uint32 planId);

}

File 9 of 20 : ICaskVault.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol";

/**
 * @title  Interface for vault
  */

interface ICaskVault is IERC20MetadataUpgradeable {

    // whitelisted stablecoin assets supported by the vault
    struct Asset {
        address priceFeed;
        uint256 slippageBps;
        uint256 depositLimit;
        uint8 assetDecimals;
        uint8 priceFeedDecimals;
        bool allowed;
    }

    enum PriceFeedType {
        Chainlink,
        Band
    }

    // sources for payments
    enum FundingSource {
        Cask,
        Personal
    }

    // funding profile for a given address
    struct FundingProfile {
        FundingSource fundingSource;
        address fundingAsset;
    }

    /**
      * @dev Get base asset of vault.
     */
    function getBaseAsset() external view returns (address);

    /**
      * @dev Get all the assets supported by the vault.
     */
    function getAllAssets() external view returns (address[] memory);

    /**
     * @dev Get asset details
     * @param _asset Asset address
     * @return Asset Asset details
     */
    function getAsset(address _asset) external view returns(Asset memory);

    /**
     * @dev Check if the vault supports an asset
     * @param _asset Asset address
     * @return bool `true` if asset supported, `false` otherwise
     */
    function supportsAsset(address _asset) external view returns (bool);

    /**
     * @dev Pay `_value` of `baseAsset` from `_from` to `_to` initiated by an authorized protocol
     * @param _from From address
     * @param _to To address
     * @param _value Amount of baseAsset value to transfer
     * @param _protocolFee Protocol fee to deduct from `_value`
     * @param _network Address of network fee collector
     * @param _networkFee Network fee to deduct from `_value`
     */
    function protocolPayment(
        address _from,
        address _to,
        uint256 _value,
        uint256 _protocolFee,
        address _network,
        uint256 _networkFee
    ) external;

    /**
     * @dev Pay `_value` of `baseAsset` from `_from` to `_to` initiated by an authorized protocol
     * @param _from From address
     * @param _to To address
     * @param _value Amount of baseAsset value to transfer
     * @param _protocolFee Protocol fee to deduct from `_value`
     */
    function protocolPayment(
        address _from,
        address _to,
        uint256 _value,
        uint256 _protocolFee
    ) external;

    /**
     * @dev Pay `_value` of `baseAsset` from `_from` to `_to` initiated by an authorized protocol
     * @param _from From address
     * @param _to To address
     * @param _value Amount of baseAsset value to transfer
     */
    function protocolPayment(
        address _from,
        address _to,
        uint256 _value
    ) external;

    /**
     * @dev Transfer the equivalent vault shares of base asset `value` to `_recipient`
     * @param _recipient To address
     * @param _value Amount of baseAsset value to transfer
     */
    function transferValue(
        address _recipient,
        uint256 _value
    ) external returns (bool);

    /**
     * @dev Transfer the equivalent vault shares of base asset `value` from `_sender` to `_recipient`
     * @param _sender From address
     * @param _recipient To address
     * @param _value Amount of baseAsset value to transfer
     */
    function transferValueFrom(
        address _sender,
        address _recipient,
        uint256 _value
    ) external returns (bool);

    /**
     * @dev Deposit `_assetAmount` of `_asset` into the vault and credit the equivalent value of `baseAsset`
     * @param _asset Address of incoming asset
     * @param _assetAmount Amount of asset to deposit
     */
    function deposit(address _asset, uint256 _assetAmount) external;

    /**
     * @dev Deposit `_assetAmount` of `_asset` into the vault and credit the equivalent value of `baseAsset`
     * @param _to Recipient of funds
     * @param _asset Address of incoming asset
     * @param _assetAmount Amount of asset to deposit
     */
    function depositTo(address _to, address _asset, uint256 _assetAmount) external;

    /**
     * @dev Withdraw an amount of shares from the vault in the form of `_asset`
     * @param _asset Address of outgoing asset
     * @param _shares Amount of shares to withdraw
     */
    function withdraw(address _asset, uint256 _shares) external;

    /**
     * @dev Withdraw an amount of shares from the vault in the form of `_asset`
     * @param _recipient Recipient who will receive the withdrawn assets
     * @param _asset Address of outgoing asset
     * @param _shares Amount of shares to withdraw
     */
    function withdrawTo(address _recipient, address _asset, uint256 _shares) external;

    /**
     * @dev Retrieve the funding source for an address
     * @param _address Address for lookup
     */
    function fundingSource(address _address) external view returns(FundingProfile memory);

    /**
     * @dev Set the funding source and, if using a personal wallet, the asset to use for funding payments
     * @param _fundingSource Funding source to use
     * @param _fundingAsset Asset to use for payments (if using personal funding source)
     */
    function setFundingSource(FundingSource _fundingSource, address _fundingAsset) external;

    /**
     * @dev Get current vault value of `_address` denominated in `baseAsset`
     * @param _address Address to check
     */
    function currentValueOf(address _address) external view returns(uint256);

    /**
     * @dev Get current vault value a vault share
     */
    function pricePerShare() external view returns(uint256);

    /**
     * @dev Get the number of vault shares that represents a given value of the base asset
     * @param _value Amount of value
     */
    function sharesForValue(uint256 _value) external view returns(uint256);

    /**
     * @dev Get total value in vault and managed by admin - denominated in `baseAsset`
     */
    function totalValue() external view returns(uint256);

    /**
     * @dev Get total amount of an asset held in vault and managed by admin
     * @param _asset Address of asset
     */
    function totalAssetBalance(address _asset) external view returns(uint256);


    /************************** EVENTS **************************/

    /** @dev Emitted when `sender` transfers `baseAssetValue` (denominated in vault baseAsset) to `recipient` */
    event TransferValue(address indexed from, address indexed to, uint256 baseAssetAmount, uint256 shares);

    /** @dev Emitted when an amount of `baseAsset` is paid from `from` to `to` within the vault */
    event Payment(address indexed from, address indexed to, uint256 baseAssetAmount, uint256 shares,
        uint256 protocolFee, uint256 protocolFeeShares,
        address indexed network, uint256 networkFee, uint256 networkFeeShares);

    /** @dev Emitted when `asset` is added as a new supported asset */
    event AllowedAsset(address indexed asset);

    /** @dev Emitted when `asset` is disallowed t */
    event DisallowedAsset(address indexed asset);

    /** @dev Emitted when `participant` deposits `asset` */
    event AssetDeposited(address indexed participant, address indexed asset, uint256 assetAmount,
        uint256 baseAssetAmount, uint256 shares);

    /** @dev Emitted when `participant` withdraws `asset` */
    event AssetWithdrawn(address indexed participant, address indexed asset, uint256 assetAmount,
        uint256 baseAssetAmount, uint256 shares);

    /** @dev Emitted when `participant` sets their funding source */
    event SetFundingSource(address indexed participant, FundingSource fundingSource, address fundingAsset);

    /** @dev Emitted when a new protocol is allowed to use the vault */
    event AddProtocol(address indexed protocol);

    /** @dev Emitted when a protocol is no longer allowed to use the vault */
    event RemoveProtocol(address indexed protocol);

    /** @dev Emitted when the vault price feed type is changed */
    event SetPriceFeedType(PriceFeedType priceFeedType);

    /** @dev Emitted when the vault fee distributor is changed */
    event SetFeeDistributor(address indexed feeDistributor);

    /** @dev Emitted when minDeposit is changed */
    event SetMinDeposit(uint256 minDeposit);

    /** @dev Emitted when maxPriceFeedAge is changed */
    event SetMaxPriceFeedAge(uint256 maxPriceFeedAge);

    /** @dev Emitted when the trustedForwarder address is changed */
    event SetTrustedForwarder(address indexed feeDistributor);
}

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.0;

import "./IERC721Upgradeable.sol";
import "./IERC721ReceiverUpgradeable.sol";
import "./extensions/IERC721MetadataUpgradeable.sol";
import "../../utils/AddressUpgradeable.sol";
import "../../utils/ContextUpgradeable.sol";
import "../../utils/StringsUpgradeable.sol";
import "../../utils/introspection/ERC165Upgradeable.sol";
import "../../proxy/utils/Initializable.sol";

/**
 * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
 * the Metadata extension, but not including the Enumerable extension, which is available separately as
 * {ERC721Enumerable}.
 */
contract ERC721Upgradeable is Initializable, ContextUpgradeable, ERC165Upgradeable, IERC721Upgradeable, IERC721MetadataUpgradeable {
    using AddressUpgradeable for address;
    using StringsUpgradeable for uint256;

    // Token name
    string private _name;

    // Token symbol
    string private _symbol;

    // Mapping from token ID to owner address
    mapping(uint256 => address) private _owners;

    // Mapping owner address to token count
    mapping(address => uint256) private _balances;

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

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

    /**
     * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
     */
    function __ERC721_init(string memory name_, string memory symbol_) internal onlyInitializing {
        __Context_init_unchained();
        __ERC165_init_unchained();
        __ERC721_init_unchained(name_, symbol_);
    }

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

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

    /**
     * @dev See {IERC721-balanceOf}.
     */
    function balanceOf(address owner) public view virtual override returns (uint256) {
        require(owner != address(0), "ERC721: balance query for the zero address");
        return _balances[owner];
    }

    /**
     * @dev See {IERC721-ownerOf}.
     */
    function ownerOf(uint256 tokenId) public view virtual override returns (address) {
        address owner = _owners[tokenId];
        require(owner != address(0), "ERC721: owner query for nonexistent token");
        return owner;
    }

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

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

    /**
     * @dev See {IERC721Metadata-tokenURI}.
     */
    function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
        require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");

        string memory baseURI = _baseURI();
        return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : "";
    }

    /**
     * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
     * token will be the concatenation of the `baseURI` and the `tokenId`. Empty
     * by default, can be overriden in child contracts.
     */
    function _baseURI() internal view virtual returns (string memory) {
        return "";
    }

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

        require(
            _msgSender() == owner || isApprovedForAll(owner, _msgSender()),
            "ERC721: approve caller is not owner nor approved for all"
        );

        _approve(to, tokenId);
    }

    /**
     * @dev See {IERC721-getApproved}.
     */
    function getApproved(uint256 tokenId) public view virtual override returns (address) {
        require(_exists(tokenId), "ERC721: approved query for nonexistent token");

        return _tokenApprovals[tokenId];
    }

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

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

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

        _transfer(from, to, tokenId);
    }

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

    /**
     * @dev See {IERC721-safeTransferFrom}.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId,
        bytes memory _data
    ) public virtual override {
        require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
        _safeTransfer(from, to, tokenId, _data);
    }

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

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

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

    /**
     * @dev Safely mints `tokenId` and transfers it to `to`.
     *
     * Requirements:
     *
     * - `tokenId` must not exist.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function _safeMint(address to, uint256 tokenId) internal virtual {
        _safeMint(to, tokenId, "");
    }

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

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

        _beforeTokenTransfer(address(0), to, tokenId);

        _balances[to] += 1;
        _owners[tokenId] = to;

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

    /**
     * @dev Destroys `tokenId`.
     * The approval is cleared when the token is burned.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     *
     * Emits a {Transfer} event.
     */
    function _burn(uint256 tokenId) internal virtual {
        address owner = ERC721Upgradeable.ownerOf(tokenId);

        _beforeTokenTransfer(owner, address(0), tokenId);

        // Clear approvals
        _approve(address(0), tokenId);

        _balances[owner] -= 1;
        delete _owners[tokenId];

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

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

        _beforeTokenTransfer(from, to, tokenId);

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

        _balances[from] -= 1;
        _balances[to] += 1;
        _owners[tokenId] = to;

        emit Transfer(from, to, tokenId);
    }

    /**
     * @dev Approve `to` to operate on `tokenId`
     *
     * Emits a {Approval} event.
     */
    function _approve(address to, uint256 tokenId) internal virtual {
        _tokenApprovals[tokenId] = to;
        emit Approval(ERC721Upgradeable.ownerOf(tokenId), to, tokenId);
    }

    /**
     * @dev Approve `operator` to operate on all of `owner` tokens
     *
     * Emits a {ApprovalForAll} event.
     */
    function _setApprovalForAll(
        address owner,
        address operator,
        bool approved
    ) internal virtual {
        require(owner != operator, "ERC721: approve to caller");
        _operatorApprovals[owner][operator] = approved;
        emit ApprovalForAll(owner, operator, approved);
    }

    /**
     * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
     * The call is not executed if the target address is not a contract.
     *
     * @param from address representing the previous owner of the given token ID
     * @param to target address that will receive the tokens
     * @param tokenId uint256 ID of the token to be transferred
     * @param _data bytes optional data to send along with the call
     * @return bool whether the call correctly returned the expected magic value
     */
    function _checkOnERC721Received(
        address from,
        address to,
        uint256 tokenId,
        bytes memory _data
    ) private returns (bool) {
        if (to.isContract()) {
            try IERC721ReceiverUpgradeable(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) {
                return retval == IERC721ReceiverUpgradeable.onERC721Received.selector;
            } catch (bytes memory reason) {
                if (reason.length == 0) {
                    revert("ERC721: transfer to non ERC721Receiver implementer");
                } else {
                    assembly {
                        revert(add(32, reason), mload(reason))
                    }
                }
            }
        } else {
            return true;
        }
    }

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

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.0;

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

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

pragma solidity ^0.8.0;

import "../IERC721Upgradeable.sol";

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

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

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

File 16 of 20 : StringsUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Strings.sol)

pragma solidity ^0.8.0;

/**
 * @dev String operations.
 */
library StringsUpgradeable {
    bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";

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

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

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        if (value == 0) {
            return "0x00";
        }
        uint256 temp = value;
        uint256 length = 0;
        while (temp != 0) {
            length++;
            temp >>= 8;
        }
        return toHexString(value, length);
    }

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

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

pragma solidity ^0.8.0;

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

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

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

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

pragma solidity ^0.8.0;

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

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

pragma solidity ^0.8.0;

import "../IERC20Upgradeable.sol";

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

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

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

File 20 of 20 : IERC20Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20Upgradeable {
    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` tokens from the caller's account to `recipient`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address recipient, uint256 amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `sender` to `recipient` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address sender,
        address recipient,
        uint256 amount
    ) external returns (bool);

    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);
}

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

Contract ABI

[{"inputs":[],"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"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[],"name":"SetParameters","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"limit","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"renewals","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"depth","type":"uint256"},{"indexed":false,"internalType":"enum ICaskSubscriptionManager.CheckType","name":"checkType","type":"uint8"},{"indexed":false,"internalType":"uint256","name":"queueRemaining","type":"uint256"},{"indexed":false,"internalType":"uint32","name":"currentBucket","type":"uint32"}],"name":"SubscriptionManagerReport","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"inputs":[{"internalType":"bytes","name":"checkData","type":"bytes"}],"name":"checkUpkeep","outputs":[{"internalType":"bool","name":"upkeepNeeded","type":"bool"},{"internalType":"bytes","name":"performData","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_vault","type":"address"},{"internalType":"address","name":"_subscriptionPlans","type":"address"},{"internalType":"address","name":"_subscriptions","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"paymentFeeMin","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"paymentFeeRateMax","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"paymentFeeRateMin","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"paymentMinValue","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"paymentRetryDelay","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"performData","type":"bytes"}],"name":"performUpkeep","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"processBucketMaxAge","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"processBucketSize","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_consumer","type":"address"},{"internalType":"address","name":"_provider","type":"address"},{"internalType":"uint256","name":"_subscriptionId","type":"uint256"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"processSinglePayment","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"enum ICaskSubscriptionManager.CheckType","name":"_checkType","type":"uint8"},{"internalType":"uint32","name":"_bucket","type":"uint32"},{"internalType":"uint256","name":"_idx","type":"uint256"}],"name":"queueItem","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"enum ICaskSubscriptionManager.CheckType","name":"_checkType","type":"uint8"}],"name":"queuePosition","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"enum ICaskSubscriptionManager.CheckType","name":"_checkType","type":"uint8"},{"internalType":"uint32","name":"_bucket","type":"uint32"}],"name":"queueSize","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_subscriptionId","type":"uint256"}],"name":"renewSubscription","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_paymentMinValue","type":"uint256"},{"internalType":"uint256","name":"_paymentFeeMin","type":"uint256"},{"internalType":"uint256","name":"_paymentFeeRateMin","type":"uint256"},{"internalType":"uint256","name":"_paymentFeeRateMax","type":"uint256"},{"internalType":"uint256","name":"_stakeTargetFactor","type":"uint256"},{"internalType":"uint32","name":"_processBucketSize","type":"uint32"},{"internalType":"uint32","name":"_processBucketMaxAge","type":"uint32"},{"internalType":"uint32","name":"_paymentRetryDelay","type":"uint32"}],"name":"setParameters","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"enum ICaskSubscriptionManager.CheckType","name":"_checkType","type":"uint8"},{"internalType":"uint32","name":"_timestamp","type":"uint32"}],"name":"setProcessingBucket","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"stakeTargetFactor","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"subscriptionPlans","outputs":[{"internalType":"contract ICaskSubscriptionPlans","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"subscriptions","outputs":[{"internalType":"contract ICaskSubscriptions","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"vault","outputs":[{"internalType":"contract ICaskVault","name":"","type":"address"}],"stateMutability":"view","type":"function"}]

60806040523480156200001157600080fd5b50600054610100900460ff166200002f5760005460ff161562000039565b62000039620000de565b620000a15760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b606482015260840160405180910390fd5b600054610100900460ff16158015620000c4576000805461ffff19166101011790555b8015620000d7576000805461ff00191690555b5062000102565b6000620000f630620000fc60201b620012771760201c565b15905090565b3b151590565b61303680620001126000396000f3fe608060405234801561001057600080fd5b50600436106101a95760003560e01c806393357f58116100f9578063c54c58c411610097578063d71bb37b11610071578063d71bb37b14610358578063eab01b801461036b578063f2fde38b14610383578063fbfa77cf1461039657600080fd5b8063c54c58c41461032c578063c5daa6c01461033f578063c83cbe891461034f57600080fd5b8063aa878f76116100d3578063aa878f76146102ea578063b8e381e5146102fd578063badf4b3e14610310578063c0c53b8b1461031957600080fd5b806393357f58146102b45780639bf4654e146102c4578063a76d67b8146102d757600080fd5b80634585e33b11610166578063715018a611610140578063715018a61461026c5780638456cb59146102745780638da5cb5b1461027c5780638fe17b16146102a157600080fd5b80634585e33b146102215780635c975abb146102345780636e04ff0d1461024b57600080fd5b806308e27a99146101ae57806314fad707146101ca5780631c39033c146101dd578063219e24c5146102055780633d3ce9261461020e5780633f4ba83a14610217575b600080fd5b6101b7609d5481565b6040519081526020015b60405180910390f35b6101b76101d83660046126bf565b6103a9565b6101f06101eb366004612700565b610423565b60405163ffffffff90911681526020016101c1565b6101b7609b5481565b6101b760a15481565b61021f610469565b005b61021f61022f36600461271d565b6104a6565b60655460ff165b60405190151581526020016101c1565b61025e61025936600461271d565b6109f1565b6040516101c19291906127bb565b61021f610bfb565b61021f610c2f565b6033546001600160a01b03165b6040516001600160a01b0390911681526020016101c1565b609754610289906001600160a01b031681565b609e546101f09063ffffffff1681565b61021f6102d23660046127f7565b610c61565b61021f6102e5366004612873565b610e89565b6101b76102f8366004612873565b610f13565b609854610289906001600160a01b031681565b6101b7609c5481565b61021f6103273660046128c1565b610f68565b61023b61033a36600461290c565b61114b565b60a2546101f09063ffffffff1681565b6101b7609a5481565b61021f610366366004612952565b6111b0565b60a2546101f090640100000000900463ffffffff1681565b61021f61039136600461296b565b6111df565b609954610289906001600160a01b031681565b6000609f60008560028111156103c1576103c1612988565b60028111156103d2576103d2612988565b815260200190815260200160002060008463ffffffff1663ffffffff168152602001908152602001600020828154811061040e5761040e61299e565b906000526020600020015490505b9392505050565b600060a0600083600281111561043b5761043b612988565b600281111561044c5761044c612988565b815260208101919091526040016000205463ffffffff1692915050565b6033546001600160a01b0316331461049c5760405162461bcd60e51b8152600401610493906129b4565b60405180910390fd5b6104a461127d565b565b60655460ff16156104c95760405162461bcd60e51b8152600401610493906129e9565b600080806104d984860186612a13565b92509250925060006104e9611310565b90506000806104f9866005612a57565b905060a0600085600281111561051157610511612988565b600281111561052257610522612988565b815260208101919091526040016000205463ffffffff16610592578260a0600086600281111561055457610554612988565b600281111561056557610565612988565b815260200190815260200160002060006101000a81548163ffffffff021916908363ffffffff1602179055505b85821080156105a15750600081115b80156105f057508263ffffffff1660a060008660028111156105c5576105c5612988565b60028111156105d6576105d6612988565b815260208101919091526040016000205463ffffffff1611155b156108e1576000609f600086600281111561060d5761060d612988565b600281111561061e5761061e612988565b8152602001908152602001600020600060a0600088600281111561064457610644612988565b600281111561065557610655612988565b8152602080820192909252604090810160009081205463ffffffff16845291830193909352910190205490508015610800576000609f600087600281111561069f5761069f612988565b60028111156106b0576106b0612988565b8152602001908152602001600020600060a060008960028111156106d6576106d6612988565b60028111156106e7576106e7612988565b8152602080820192909252604090810160009081205463ffffffff168452918301939093529101902061071b600184612a76565b8154811061072b5761072b61299e565b90600052602060002001549050609f600087600281111561074e5761074e612988565b600281111561075f5761075f612988565b8152602001908152602001600020600060a0600089600281111561078557610785612988565b600281111561079657610796612988565b8152602080820192909252604090810160009081205463ffffffff16845291830193909352910190208054806107ce576107ce612a8d565b600190038181906000526020600020016000905590556107ed81611338565b6107f8600185612aa3565b9350506108db565b8363ffffffff1660a0600087600281111561081d5761081d612988565b600281111561082e5761082e612988565b815260208101919091526040016000205463ffffffff1610156108d557609e5463ffffffff1660a0600087600281111561086a5761086a612988565b600281111561087b5761087b612988565b81526020810191909152604001600090812080549091906108a390849063ffffffff16612abb565b92506101000a81548163ffffffff021916908363ffffffff1602179055506001826108ce9190612a76565b91506108db565b506108e1565b50610592565b7f75a64c7d044cacf7f5733a40d9f770446e4a977483bf14d9e58752255a62785386838787609f60008a600281111561091c5761091c612988565b600281111561092d5761092d612988565b8152602001908152602001600020600060a060008c600281111561095357610953612988565b600281111561096457610964612988565b8152602080820192909252604090810160009081205463ffffffff1684529183019390935291018120549060a0908b60028111156109a4576109a4612988565b60028111156109b5576109b5612988565b8152602081019190915260409081016000205490516109df96959493929163ffffffff1690612af7565b60405180910390a15050505050505050565b60006060818080610a0486880188612a13565b9250925092506000610a14611310565b905060009550600060a06000846002811115610a3257610a32612988565b6002811115610a4357610a43612988565b815260208101919091526040016000205463ffffffff16905080610a645750805b8063ffffffff168263ffffffff1610158015610a96575060a25463ffffffff16610a8e8284612b36565b63ffffffff16115b15610aa45760019650610b83565b8163ffffffff168163ffffffff1611610b83576000609f6000856002811115610acf57610acf612988565b6002811115610ae057610ae0612988565b81526020808201929092526040908101600090812063ffffffff86168252909252902054118015610b5b575083609f6000856002811115610b2357610b23612988565b6002811115610b3457610b34612988565b81526020808201929092526040908101600090812063ffffffff8616825290925290205410155b15610b695760019650610b83565b609e54610b7c9063ffffffff1682612abb565b9050610aa4565b84609f6000856002811115610b9a57610b9a612988565b6002811115610bab57610bab612988565b81526020808201929092526040908101600090812063ffffffff861682528352819020549051610bde9392879101612b5b565b604051602081830303815290604052955050505050509250929050565b6033546001600160a01b03163314610c255760405162461bcd60e51b8152600401610493906129b4565b6104a46000611d50565b6033546001600160a01b03163314610c595760405162461bcd60e51b8152600401610493906129b4565b6104a4611da2565b6033546001600160a01b03163314610c8b5760405162461bcd60e51b8152600401610493906129b4565b6127108610610cdc5760405162461bcd60e51b815260206004820152601b60248201527f21494e56414c4944287061796d656e74466565526174654d696e2900000000006044820152606401610493565b6127108510610d2d5760405162461bcd60e51b815260206004820152601b60248201527f21494e56414c4944287061796d656e74466565526174654d61782900000000006044820152606401610493565b60a1889055609a879055609b869055609c859055609d849055609e805463ffffffff191663ffffffff8581169190911790915560a2805484831667ffffffffffffffff199091161764010000000092841692909202919091179055610dbf60a0600060015b6002811115610da357610da3612988565b815260208101919091526040016000205463ffffffff16611dfa565b6001600090815260a060208190527f5e4aa62fc514c001129aba2f8cfdadfdbf7b1cca3faf4a1fee3af14b1315f0dd805463ffffffff191663ffffffff9490941693909317909255610e1391906002610d92565b6002600090815260a06020527e3e94880a29ff53e6a8208a04e96e212c12922b7bda6b10d8c1979e9844e678805463ffffffff191663ffffffff93909316929092179091556040517f3b5fda6f71b960b21be0b432d9b7c87d9c8c996477ea1eba5c19cb77d1e027aa9190a15050505050505050565b6033546001600160a01b03163314610eb35760405162461bcd60e51b8152600401610493906129b4565b610ebc81611dfa565b60a06000846002811115610ed257610ed2612988565b6002811115610ee357610ee3612988565b815260200190815260200160002060006101000a81548163ffffffff021916908363ffffffff1602179055505050565b6000609f6000846002811115610f2b57610f2b612988565b6002811115610f3c57610f3c612988565b81526020808201929092526040908101600090812063ffffffff86168252909252902054905092915050565b600054610100900460ff16610f835760005460ff1615610f87565b303b155b610fea5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610493565b600054610100900460ff1615801561100c576000805461ffff19166101011790555b611014611e2a565b61101c611e61565b609780546001600160a01b038086166001600160a01b031992831617909255609880548584169083161790556099805492871692909116919091179055600060a1819055609a819055609b819055609c819055609d55609e805463ffffffff191661012c17905560a2805465a8c000000e1067ffffffffffffffff199091161790556110a6611310565b600160005260a06020527f5e4aa62fc514c001129aba2f8cfdadfdbf7b1cca3faf4a1fee3af14b1315f0dd805463ffffffff191663ffffffff929092169190911790556110f1611310565b600260005260a06020527e3e94880a29ff53e6a8208a04e96e212c12922b7bda6b10d8c1979e9844e678805463ffffffff191663ffffffff929092169190911790558015611145576000805461ff00191690555b50505050565b6098546000906001600160a01b0316336001600160a01b0316146111995760405162461bcd60e51b815260206004820152600560248201526404282aaa8960db1b6044820152606401610493565b6111a585858585611e98565b90505b949350505050565b60655460ff16156111d35760405162461bcd60e51b8152600401610493906129e9565b6111dc81611338565b50565b6033546001600160a01b031633146112095760405162461bcd60e51b8152600401610493906129b4565b6001600160a01b03811661126e5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610493565b6111dc81611d50565b3b151590565b60655460ff166112c65760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610493565b6065805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b609e5460009042906113289063ffffffff1682612b8c565b6113329082612b36565b91505090565b60985460405163dc311dd360e01b81526004810183905260009182916001600160a01b039091169063dc311dd39060240160006040518083038186803b15801561138157600080fd5b505afa158015611395573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526113bd9190810190612ca1565b90925090504260038360c0015160068111156113db576113db612988565b14806113fc575060048360c0015160068111156113fa576113fa612988565b145b8061141c575060008360c00151600681111561141a5761141a612988565b145b156114275750505050565b8063ffffffff1683610120015163ffffffff1611156114af5760016000908152609f6020526101208401517fd8ebc4b3e3fc84fb7267bc9651f22e5107e8b4ddef6b7d4ac503c1ca7368470b919061147e90611dfa565b63ffffffff168152602080820192909252604001600090812080546001810182559082529190200193909355505050565b60068360c0015160068111156114c7576114c7612988565b141561153857609854604051633efbd95560e11b81526001600160a01b0390911690637df7b2aa90611500908790600690600401612df7565b600060405180830381600087803b15801561151a57600080fd5b505af115801561152e573d6000803e3d6000fd5b5050505050505050565b600083610160015163ffffffff1611801561156457508063ffffffff1683610160015163ffffffff1611155b806116c95750600260975460a085015160e086015160405163b6ab359f60e01b81526001600160a01b03928316600482015263ffffffff909116602482015291169063b6ab359f9060440160206040518083038186803b1580156115c757600080fd5b505afa1580156115db573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115ff9190612e1b565b600281111561161057611610612988565b1480156116c9575060975460a084015160e085015160405163025b687560e01b815263ffffffff8516936001600160a01b03169263025b687592611670926004016001600160a01b0392909216825263ffffffff16602082015260400190565b60206040518083038186803b15801561168857600080fd5b505afa15801561169c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116c09190612e38565b63ffffffff1611155b1561170157609854604051633efbd95560e11b81526001600160a01b0390911690637df7b2aa90611500908790600290600401612df7565b60985460405163321b9a5560e21b8152600481018690526000916001600160a01b03169063c86e69549060240160206040518083038186803b15801561174657600080fd5b505afa15801561175a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061177e9190612e55565b111561186d57609854604051633efbd95560e11b81526001600160a01b0390911690637df7b2aa906117b7908790600190600401612df7565b600060405180830381600087803b1580156117d157600080fd5b505af11580156117e5573d6000803e3d6000fd5b505060985460405163dc311dd360e01b8152600481018890526001600160a01b03909116925063dc311dd3915060240160006040518083038186803b15801561182d57600080fd5b505afa158015611841573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526118699190810190612ca1565b5092505b600061187c846000015161212a565b80519091508061188e57505050505050565b6040850151156119c35760006118a78660600151612205565b90508060a0015161ffff16600014806118f257508363ffffffff168160a0015161ffff1684604001516118da9190612e6e565b8761010001516118ea9190612abb565b63ffffffff16115b1561195b57611906858760400151836122ed565b156119565760008160e00151611935578151612710906119269085612a57565b6119309190612e9a565b611938565b81515b9050808311611948576000611952565b6119528184612a76565b9250505b6119c1565b609854604051633efbd95560e11b81526001600160a01b0390911690637df7b2aa9061198e908a90600590600401612df7565b600060405180830381600087803b1580156119a857600080fd5b505af11580156119bc573d6000803e3d6000fd5b505050505b505b60a1548110806119d55750609a548111155b15611a4457609854604051633efbd95560e11b81526001600160a01b0390911690637df7b2aa90611a0d908990600290600401612df7565b600060405180830381600087803b158015611a2757600080fd5b505af1158015611a3b573d6000803e3d6000fd5b50505050611d48565b611a54848660a001518884611e98565b15611b93578263ffffffff168260400151866101200151611a759190612abb565b63ffffffff161015611ae85760026000908152609f6020527f95684aba87c7afc0cb0825ce802e59a0c43a91e65441705f8ec2d377a306a58790611ab885611dfa565b63ffffffff1681526020808201929092526040016000908120805460018101825590825291902001869055611b61565b60016000908152609f60205260408301516101208701517fd8ebc4b3e3fc84fb7267bc9651f22e5107e8b4ddef6b7d4ac503c1ca7368470b9291611b3591611b309190612abb565b611dfa565b63ffffffff16815260208082019290925260400160009081208054600181018255908252919020018690555b609854604051633efbd95560e11b81526001600160a01b0390911690637df7b2aa90611a0d9089906004908101612df7565b60c0820151611ba89060ff1662015180612eae565b611bb79062ffffff1684612b36565b63ffffffff1685610120015163ffffffff161015611c0257609854604051633efbd95560e11b81526001600160a01b0390911690637df7b2aa90611a0d908990600290600401612df7565b60058560c001516006811115611c1a57611c1a612988565b14611cce5760026000908152609f60205260a2547f95684aba87c7afc0cb0825ce802e59a0c43a91e65441705f8ec2d377a306a5879190611c6d90611b3090640100000000900463ffffffff1687612abb565b63ffffffff1681526020808201929092526040908101600090812080546001810182559082529290209091018790556098549051633efbd95560e11b81526001600160a01b0390911690637df7b2aa90611a0d908990600390600401612df7565b60026000908152609f60205260a2547f95684aba87c7afc0cb0825ce802e59a0c43a91e65441705f8ec2d377a306a5879190611d1c90611b3090640100000000900463ffffffff1687612abb565b63ffffffff16815260208082019290925260400160009081208054600181018255908252919020018690555b505050505050565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b60655460ff1615611dc55760405162461bcd60e51b8152600401610493906129e9565b6065805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586112f33390565b609e5460009063ffffffff16611e108184612b8c565b611e1a9084612b36565b611e249190612abb565b92915050565b600054610100900460ff16611e515760405162461bcd60e51b815260040161049390612ed0565b611e596123ca565b6104a46123f1565b600054610100900460ff16611e885760405162461bcd60e51b815260040161049390612ed0565b611e906123ca565b6104a4612421565b60985460405163dc311dd360e01b81526004810184905260009182916001600160a01b039091169063dc311dd39060240160006040518083038186803b158015611ee157600080fd5b505afa158015611ef5573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611f1d9190810190612ca1565b50609c54609d54919250901561207557600080611f3d846000015161212a565b9050600082118015611f5957506000816040015163ffffffff16115b15612072576000620151808260400151611f739190612f1b565b611f7f9061016d612f1b565b609d5460985460a08801516040516374c1443960e01b81526001600160a01b0391821660048201526000602482018190526044820181905263ffffffff95909516955085939291909116906374c144399060640160206040518083038186803b158015611feb57600080fd5b505afa158015611fff573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120239190612e55565b61202d9190612a57565b6120379190612a57565b90506120438185612e9a565b609c546120509190612a57565b609c5461205d9190612a76565b9450609b5485101561206f57609b5494505b50505b50505b609754604051630782fb5960e31b81526001600160a01b0388811660048301526000921690633c17dac89060240160006040518083038186803b1580156120bb57600080fd5b505afa1580156120cf573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526120f79190810190612f3e565b805190915087906001600160a01b031615612110575080515b61211d848a838987612454565b9998505050505050505050565b6040805161012081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e0810182905261010081019190915250604080516101208101825260a083811c8252608084811c63ffffffff908116602080860191909152606087811c8316868801529587901c8216958501959095529385901c90931692820192909252601083901c61ffff1691810191909152600882901c60ff1660c082015260f89190911b600160f81b8181161460e0830152600160f91b9081161461010082015290565b6040805161010081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e0810191909152604080516101008101825260a084811c825263ffffffff608086811c8216602080860191909152606088811c8416868801529588901c8316958501959095529386901c169282019290925261ffff601085901c169181019190915260f083901b9060c0810160ff851660028111156122c0576122c0612988565b60028111156122d1576122d1612988565b8152600160f81b92831690921460209092019190915292915050565b600060018260c00151600281111561230757612307612988565b14156123155750600161041c565b60028260c00151600281111561232d5761232d612988565b14156123c05760975460405163cd1402e760e01b81526001600160a01b038681166004830152602482018690529091169063cd1402e790604401602060405180830381600087803b15801561238157600080fd5b505af1158015612395573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123b99190612fde565b905061041c565b5060009392505050565b600054610100900460ff166104a45760405162461bcd60e51b815260040161049390612ed0565b600054610100900460ff166124185760405162461bcd60e51b815260040161049390612ed0565b6104a433611d50565b600054610100900460ff166124485760405162461bcd60e51b815260040161049390612ed0565b6065805460ff19169055565b6000806127106124648486612a57565b61246e9190612e9a565b9050609a5481101561247f5750609a545b6020870151156125d55760006124cb886020015160408051808201909152600080825260208201525060408051808201909152606082901c815260509190911c61ffff16602082015290565b90506000612710826020015161ffff16876124e69190612a57565b6124f09190612e9a565b90506124fc8184612aa3565b861161253b5760405162461bcd60e51b815260206004820152600e60248201526d2156414c55455f544f4f5f4c4f5760901b6044820152606401610493565b60995482516040516379b2125f60e01b81526001600160a01b038b811660048301528a81166024830152604482018a905260648201879052918216608482015260a481018490529116906379b2125f9060c401600060405180830381600087803b1580156125a857600080fd5b505af19250505080156125b9575060015b6125c95760009350505050612697565b60019350505050612697565b8084116126155760405162461bcd60e51b815260206004820152600e60248201526d2156414c55455f544f4f5f4c4f5760901b6044820152606401610493565b60995460405163fcd6a25b60e01b81526001600160a01b038881166004830152878116602483015260448201879052606482018490529091169063fcd6a25b90608401600060405180830381600087803b15801561267257600080fd5b505af1925050508015612683575060015b612691576000915050612697565b60019150505b95945050505050565b600381106111dc57600080fd5b63ffffffff811681146111dc57600080fd5b6000806000606084860312156126d457600080fd5b83356126df816126a0565b925060208401356126ef816126ad565b929592945050506040919091013590565b60006020828403121561271257600080fd5b813561041c816126a0565b6000806020838503121561273057600080fd5b823567ffffffffffffffff8082111561274857600080fd5b818501915085601f83011261275c57600080fd5b81358181111561276b57600080fd5b86602082850101111561277d57600080fd5b60209290920196919550909350505050565b60005b838110156127aa578181015183820152602001612792565b838111156111455750506000910152565b821515815260406020820152600082518060408401526127e281606085016020870161278f565b601f01601f1916919091016060019392505050565b600080600080600080600080610100898b03121561281457600080fd5b883597506020890135965060408901359550606089013594506080890135935060a0890135612842816126ad565b925060c0890135612852816126ad565b915060e0890135612862816126ad565b809150509295985092959890939650565b6000806040838503121561288657600080fd5b8235612891816126a0565b915060208301356128a1816126ad565b809150509250929050565b6001600160a01b03811681146111dc57600080fd5b6000806000606084860312156128d657600080fd5b83356128e1816128ac565b925060208401356128f1816128ac565b91506040840135612901816128ac565b809150509250925092565b6000806000806080858703121561292257600080fd5b843561292d816128ac565b9350602085013561293d816128ac565b93969395505050506040820135916060013590565b60006020828403121561296457600080fd5b5035919050565b60006020828403121561297d57600080fd5b813561041c816128ac565b634e487b7160e01b600052602160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60208082526010908201526f14185d5cd8589b194e881c185d5cd95960821b604082015260600190565b600080600060608486031215612a2857600080fd5b83359250602084013591506040840135612901816126a0565b634e487b7160e01b600052601160045260246000fd5b6000816000190483118215151615612a7157612a71612a41565b500290565b600082821015612a8857612a88612a41565b500390565b634e487b7160e01b600052603160045260246000fd5b60008219821115612ab657612ab6612a41565b500190565b600063ffffffff808316818516808303821115612ada57612ada612a41565b01949350505050565b60038110612af357612af3612988565b9052565b868152602081018690526040810185905260c08101612b196060830186612ae3565b83608083015263ffffffff831660a0830152979650505050505050565b600063ffffffff83811690831681811015612b5357612b53612a41565b039392505050565b83815260208101839052606081016111a86040830184612ae3565b634e487b7160e01b600052601260045260246000fd5b600063ffffffff80841680612ba357612ba3612b76565b92169190910692915050565b634e487b7160e01b600052604160045260246000fd5b6040516101c0810167ffffffffffffffff81118282101715612be957612be9612baf565b60405290565b8051612bfa816128ac565b919050565b805160078110612bfa57600080fd5b8051612bfa816126ad565b600082601f830112612c2a57600080fd5b815167ffffffffffffffff80821115612c4557612c45612baf565b604051601f8301601f19908116603f01168101908282118183101715612c6d57612c6d612baf565b81604052838152866020858801011115612c8657600080fd5b612c9784602083016020890161278f565b9695505050505050565b60008060408385031215612cb457600080fd5b825167ffffffffffffffff80821115612ccc57600080fd5b908401906101c08287031215612ce157600080fd5b612ce9612bc5565b8251815260208301516020820152604083015160408201526060830151606082015260808301516080820152612d2160a08401612bef565b60a0820152612d3260c08401612bff565b60c0820152612d4360e08401612c0e565b60e0820152610100612d56818501612c0e565b90820152610120612d68848201612c0e565b90820152610140612d7a848201612c0e565b90820152610160612d8c848201612c0e565b908201526101808381015183811115612da457600080fd5b612db089828701612c19565b8284015250506101a08084015183811115612dca57600080fd5b612dd689828701612c19565b828401525050809450505050612dee60208401612bef565b90509250929050565b8281526040810160078310612e0e57612e0e612988565b8260208301529392505050565b600060208284031215612e2d57600080fd5b815161041c816126a0565b600060208284031215612e4a57600080fd5b815161041c816126ad565b600060208284031215612e6757600080fd5b5051919050565b600063ffffffff80831681851681830481118215151615612e9157612e91612a41565b02949350505050565b600082612ea957612ea9612b76565b500490565b600062ffffff80831681851681830481118215151615612e9157612e91612a41565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b600063ffffffff80841680612f3257612f32612b76565b92169190910492915050565b600060208284031215612f5057600080fd5b815167ffffffffffffffff80821115612f6857600080fd5b9083019060608286031215612f7c57600080fd5b604051606081018181108382111715612f9757612f97612baf565b6040528251612fa5816128ac565b815260208381015190820152604083015182811115612fc357600080fd5b612fcf87828601612c19565b60408301525095945050505050565b600060208284031215612ff057600080fd5b8151801515811461041c57600080fdfea26469706673582212202220a172a3342004e54ecc765ebc6e7fc819f02bb43582473396a663d7c45b2f64736f6c63430008090033

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