ETH Price: $2,818.45 (-4.46%)
 

Overview

ETH Balance

Scroll LogoScroll LogoScroll Logo0 ETH

ETH Value

$0.00

Token Holdings

More Info

Private Name Tags

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Harvest All Divi...115952432024-12-02 22:14:08418 days ago1733177648IN
Essence Finance: xZen Rewards (Dividends V2)
0 ETH0.000023250.05
Harvest All Divi...115359462024-11-30 18:25:06421 days ago1732991106IN
Essence Finance: xZen Rewards (Dividends V2)
0 ETH0.000014860.05
Harvest All Divi...114383212024-11-27 4:44:33424 days ago1732682673IN
Essence Finance: xZen Rewards (Dividends V2)
0 ETH0.000009840.04056373
Harvest All Divi...112664122024-11-20 22:36:07430 days ago1732142167IN
Essence Finance: xZen Rewards (Dividends V2)
0 ETH0.000031390.16237115
Harvest All Divi...111401642024-11-16 9:03:47435 days ago1731747827IN
Essence Finance: xZen Rewards (Dividends V2)
0 ETH0.000012560.04640126
Harvest All Divi...110258752024-11-12 6:10:07439 days ago1731391807IN
Essence Finance: xZen Rewards (Dividends V2)
0 ETH0.000023910.07
Harvest All Divi...109346682024-11-09 1:41:08442 days ago1731116468IN
Essence Finance: xZen Rewards (Dividends V2)
0 ETH0.000011070.05
Harvest All Divi...109162702024-11-08 10:12:12443 days ago1731060732IN
Essence Finance: xZen Rewards (Dividends V2)
0 ETH0.000013760.05
Harvest All Divi...108882512024-11-07 10:27:59444 days ago1730975279IN
Essence Finance: xZen Rewards (Dividends V2)
0 ETH0.000014280.0418032
Harvest All Divi...108540222024-11-06 5:49:53445 days ago1730872193IN
Essence Finance: xZen Rewards (Dividends V2)
0 ETH0.00001750.06
Harvest All Divi...108050332024-11-04 12:37:05447 days ago1730723825IN
Essence Finance: xZen Rewards (Dividends V2)
0 ETH0.000009550.04344364
Harvest All Divi...107928942024-11-04 2:28:00447 days ago1730687280IN
Essence Finance: xZen Rewards (Dividends V2)
0 ETH0.000018850.13601707
Harvest All Divi...107689242024-11-03 6:25:26448 days ago1730615126IN
Essence Finance: xZen Rewards (Dividends V2)
0 ETH0.000007090.06
Harvest All Divi...107689182024-11-03 6:25:08448 days ago1730615108IN
Essence Finance: xZen Rewards (Dividends V2)
0 ETH0.00001080.06
Harvest All Divi...107392542024-11-02 5:23:20449 days ago1730525000IN
Essence Finance: xZen Rewards (Dividends V2)
0 ETH0.000012760.07
Harvest All Divi...107224612024-11-01 15:11:05450 days ago1730473865IN
Essence Finance: xZen Rewards (Dividends V2)
0 ETH0.000018350.06
Harvest All Divi...107183122024-11-01 11:43:51450 days ago1730461431IN
Essence Finance: xZen Rewards (Dividends V2)
0 ETH0.000010860.05400468
Harvest All Divi...107143272024-11-01 8:24:55450 days ago1730449495IN
Essence Finance: xZen Rewards (Dividends V2)
0 ETH0.000008970.05
Harvest All Divi...107143202024-11-01 8:24:34450 days ago1730449474IN
Essence Finance: xZen Rewards (Dividends V2)
0 ETH0.000012290.05
Harvest All Divi...106980932024-10-31 18:51:47451 days ago1730400707IN
Essence Finance: xZen Rewards (Dividends V2)
0 ETH0.000014930.06
Harvest All Divi...106980552024-10-31 18:49:51451 days ago1730400591IN
Essence Finance: xZen Rewards (Dividends V2)
0 ETH0.000016350.06
Harvest All Divi...106980282024-10-31 18:48:32451 days ago1730400512IN
Essence Finance: xZen Rewards (Dividends V2)
0 ETH0.000017440.05
Harvest All Divi...106979872024-10-31 18:46:28451 days ago1730400388IN
Essence Finance: xZen Rewards (Dividends V2)
0 ETH0.000017740.06
Harvest All Divi...106979572024-10-31 18:45:00451 days ago1730400300IN
Essence Finance: xZen Rewards (Dividends V2)
0 ETH0.000018530.06
Harvest All Divi...106979102024-10-31 18:42:39451 days ago1730400159IN
Essence Finance: xZen Rewards (Dividends V2)
0 ETH0.00001790.06
View all transactions

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Cross-Chain Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
DividendsV2

Compiler Version
v0.8.24+commit.e11b9ed9

Optimization Enabled:
Yes with 200 runs

Other Settings:
paris EvmVersion
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";

import "./interfaces/IDividendsV2.sol";
import "./interfaces/IXZenTokenUsage.sol";

import "../../refs/CoreRef.sol";

/*
 * This contract is used to distribute dividends to users that allocated xZen here
 *
 * Dividends can be distributed in the form of one or more tokens
 * They are mainly managed to be received from the FeeManager contract, but other sources can be added (dev wallet for instance)
 *
 * The freshly received dividends are stored in a pending slot
 *
 * The content of this pending slot will be progressively transferred over time into a distribution slot
 * This distribution slot is the source of the dividends distribution to xZen allocators during the current cycle
 *
 * This transfer from the pending slot to the distribution slot is based on cycleDividendsPercent and CYCLE_PERIOD_SECONDS
 *
 */
contract DividendsV2 is CoreRef, ReentrancyGuard, IXZenTokenUsage, IDividendsV2 {
    using SafeMath for uint256;
    using SafeERC20 for IERC20;
    using EnumerableSet for EnumerableSet.AddressSet;

    struct UserInfo {
        uint256 pendingDividends;
        uint256 rewardDebt;
    }

    struct DividendsInfo {
        uint256 currentDistributionAmount; // total amount to distribute during the current cycle
        uint256 currentCycleDistributedAmount; // amount already distributed for the current cycle (times 1e2)
        uint256 pendingAmount; // total amount in the pending slot, not distributed yet
        uint256 distributedAmount; // total amount that has been distributed since initialization
        uint256 accDividendsPerShare; // accumulated dividends per share (times 1e18)
        uint256 lastUpdateTime; // last time the dividends distribution occurred
        uint256 cycleDividendsPercent; // fixed part of the pending dividends to assign to currentDistributionAmount on every cycle
        bool distributionDisabled; // deactivate a token distribution (for temporary dividends)
    }

    // actively distributed tokens
    EnumerableSet.AddressSet private _distributedTokens;
    uint256 public constant MAX_DISTRIBUTED_TOKENS = 10;

    // dividends info for every dividends token
    mapping(address => DividendsInfo) public dividendsInfo;
    mapping(address => mapping(address => UserInfo)) public users;

    address public immutable xZenToken; // xZenToken contract

    mapping(address => uint256) public usersAllocation; // User's xZen allocation
    uint256 public totalAllocation; // Contract's total xZen allocation

    uint256 public constant MIN_CYCLE_DIVIDENDS_PERCENT = 1; // 0.01%
    uint256 public constant DEFAULT_CYCLE_DIVIDENDS_PERCENT = 10000; // 100%
    uint256 public constant MAX_CYCLE_DIVIDENDS_PERCENT = 10000; // 100%
    // dividends will be added to the currentDistributionAmount on each new cycle
    uint256 internal _cycleDurationSeconds = 7 days;
    uint256 public currentCycleStartTime;

    constructor(address xZenToken_, uint256 startTime_, address _core) CoreRef(_core) {
        require(xZenToken_ != address(0), "zero address");
        xZenToken = xZenToken_;
        currentCycleStartTime = startTime_;
    }

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

    event UserUpdated(address indexed user, uint256 previousBalance, uint256 newBalance);
    event DividendsCollected(address indexed user, address indexed token, uint256 amount);
    event CycleDividendsPercentUpdated(address indexed token, uint256 previousValue, uint256 newValue);
    event DividendsAddedToPending(address indexed token, uint256 amount);
    event DistributedTokenDisabled(address indexed token);
    event DistributedTokenRemoved(address indexed token);
    event DistributedTokenEnabled(address indexed token);

    /***********************************************/
    /****************** MODIFIERS ******************/
    /***********************************************/

    /**
     * @dev Checks if an index exists
     */
    modifier validateDistributedTokensIndex(uint256 index) {
        require(index < _distributedTokens.length(), "validateDistributedTokensIndex: index exists?");
        _;
    }

    /**
     * @dev Checks if token exists
     */
    modifier validateDistributedToken(address token) {
        require(_distributedTokens.contains(token), "validateDistributedTokens: token does not exists");
        _;
    }

    /**
     * @dev Checks if caller is the xZenToken contract
     */
    modifier xZenTokenOnly() {
        require(msg.sender == xZenToken, "xZenTokenOnly: caller should be XZenToken");
        _;
    }

    /*******************************************/
    /****************** VIEWS ******************/
    /*******************************************/

    function cycleDurationSeconds() external view returns (uint256) {
        return _cycleDurationSeconds;
    }

    /**
     * @dev Returns the number of dividends tokens
     */
    function distributedTokensLength() external view override returns (uint256) {
        return _distributedTokens.length();
    }

    /**
     * @dev Returns dividends token address from given index
     */
    function distributedToken(
        uint256 index
    ) external view override validateDistributedTokensIndex(index) returns (address) {
        return address(_distributedTokens.at(index));
    }

    /**
     * @dev Returns true if given token is a dividends token
     */
    function isDistributedToken(address token) external view override returns (bool) {
        return _distributedTokens.contains(token);
    }

    /**
     * @dev Returns time at which the next cycle will start
     */
    function nextCycleStartTime() public view returns (uint256) {
        return currentCycleStartTime.add(_cycleDurationSeconds);
    }

    /**
     * @dev Returns user's dividends pending amount for a given token
     */
    function pendingDividendsAmount(address token, address userAddress) external view returns (uint256) {
        if (totalAllocation == 0) {
            return 0;
        }

        DividendsInfo storage dividendsInfo_ = dividendsInfo[token];

        uint256 accDividendsPerShare = dividendsInfo_.accDividendsPerShare;
        uint256 lastUpdateTime = dividendsInfo_.lastUpdateTime;
        uint256 dividendAmountPerSecond_ = _dividendsAmountPerSecond(token);

        // check if the current cycle has changed since last update
        if (_currentBlockTimestamp() > nextCycleStartTime()) {
            // get remaining rewards from last cycle
            accDividendsPerShare = accDividendsPerShare.add(
                (nextCycleStartTime().sub(lastUpdateTime)).mul(dividendAmountPerSecond_).mul(1e16).div(totalAllocation)
            );
            lastUpdateTime = nextCycleStartTime();
            dividendAmountPerSecond_ = dividendsInfo_
                .pendingAmount
                .mul(dividendsInfo_.cycleDividendsPercent)
                .div(100)
                .div(_cycleDurationSeconds);
        }

        // get pending rewards from current cycle
        accDividendsPerShare = accDividendsPerShare.add(
            (_currentBlockTimestamp().sub(lastUpdateTime)).mul(dividendAmountPerSecond_).mul(1e16).div(totalAllocation)
        );

        return
            usersAllocation[userAddress]
                .mul(accDividendsPerShare)
                .div(1e18)
                .sub(users[token][userAddress].rewardDebt)
                .add(users[token][userAddress].pendingDividends);
    }

    /**************************************************/
    /****************** PUBLIC FUNCTIONS **************/
    /**************************************************/

    /**
     * @dev Updates the current cycle start time if previous cycle has ended
     */
    function updateCurrentCycleStartTime() public {
        uint256 nextCycleStartTime_ = nextCycleStartTime();

        if (_currentBlockTimestamp() >= nextCycleStartTime_) {
            currentCycleStartTime = nextCycleStartTime_;
        }
    }

    /**
     * @dev Updates dividends info for a given token
     */
    function updateDividendsInfo(address token) external validateDistributedToken(token) {
        _updateDividendsInfo(token);
    }

    /****************************************************************/
    /****************** EXTERNAL PUBLIC FUNCTIONS  ******************/
    /****************************************************************/

    /**
     * @dev Updates all dividendsInfo
     */
    function massUpdateDividendsInfo() external {
        uint256 length = _distributedTokens.length();
        for (uint256 index = 0; index < length; ++index) {
            _updateDividendsInfo(_distributedTokens.at(index));
        }
    }

    /**
     * @dev Harvests caller's pending dividends of a given token
     */
    function harvestDividends(address token) external nonReentrant {
        if (!_distributedTokens.contains(token)) {
            require(dividendsInfo[token].distributedAmount > 0, "harvestDividends: invalid token");
        }

        _harvestDividends(token);
    }

    /**
     * @dev Harvests all caller's pending dividends
     */
    function harvestAllDividends() external nonReentrant {
        uint256 length = _distributedTokens.length();
        for (uint256 index = 0; index < length; ++index) {
            _harvestDividends(_distributedTokens.at(index));
        }
    }

    /**
     * @dev Transfers the given amount of token from caller to pendingAmount
     *
     * Must only be called by a trustable address
     */
    function addDividendsToPending(address token, uint256 amount) external override nonReentrant {
        uint256 prevTokenBalance = IERC20(token).balanceOf(address(this));
        DividendsInfo storage dividendsInfo_ = dividendsInfo[token];

        IERC20(token).safeTransferFrom(msg.sender, address(this), amount);

        // handle tokens with transfer tax
        uint256 receivedAmount = IERC20(token).balanceOf(address(this)).sub(prevTokenBalance);
        dividendsInfo_.pendingAmount = dividendsInfo_.pendingAmount.add(receivedAmount);

        emit DividendsAddedToPending(token, receivedAmount);
    }

    /**
     * @dev Emergency withdraw token's balance on the contract
     */
    function emergencyWithdraw(IERC20 token) public nonReentrant onlyGuardianOrGovernor {
        uint256 balance = token.balanceOf(address(this));
        require(balance > 0, "emergencyWithdraw: token balance is null");
        _safeTokenTransfer(token, msg.sender, balance);
    }

    /**
     * @dev Emergency withdraw all dividend tokens' balances on the contract
     */
    function emergencyWithdrawAll() external nonReentrant onlyGuardianOrGovernor {
        for (uint256 index = 0; index < _distributedTokens.length(); ++index) {
            emergencyWithdraw(IERC20(_distributedTokens.at(index)));
        }
    }

    /*****************************************************************/
    /****************** OWNABLE FUNCTIONS  ******************/
    /*****************************************************************/
    /**
     * Allocates "userAddress" user's "amount" of xZen to this dividends contract
     *
     * Can only be called by xZenToken contract, which is trusted to verify amounts
     * "data" is only here for compatibility reasons (IxZenTokenUsage)
     */
    function allocate(
        address userAddress,
        uint256 amount,
        bytes calldata /*data*/
    ) external override nonReentrant xZenTokenOnly {
        uint256 newUserAllocation = usersAllocation[userAddress].add(amount);
        uint256 newTotalAllocation = totalAllocation.add(amount);
        _updateUser(userAddress, newUserAllocation, newTotalAllocation);
    }

    /**
     * Deallocates "userAddress" user's "amount" of xZen allocation from this dividends contract
     *
     * Can only be called by xZenToken contract, which is trusted to verify amounts
     * "data" is only here for compatibility reasons (IxZenTokenUsage)
     */
    function deallocate(
        address userAddress,
        uint256 amount,
        bytes calldata /*data*/
    ) external override nonReentrant xZenTokenOnly {
        uint256 newUserAllocation = usersAllocation[userAddress].sub(amount);
        uint256 newTotalAllocation = totalAllocation.sub(amount);
        _updateUser(userAddress, newUserAllocation, newTotalAllocation);
    }

    /**
     * @dev Enables a given token to be distributed as dividends
     *
     * Effective from the next cycle
     */
    function enableDistributedToken(address token) external onlyGuardianOrGovernor {
        DividendsInfo storage dividendsInfo_ = dividendsInfo[token];
        require(
            dividendsInfo_.lastUpdateTime == 0 || dividendsInfo_.distributionDisabled,
            "enableDistributedToken: Already enabled dividends token"
        );
        require(
            _distributedTokens.length() < MAX_DISTRIBUTED_TOKENS,
            "enableDistributedToken: too many distributedTokens"
        );
        // initialize lastUpdateTime if never set before
        if (dividendsInfo_.lastUpdateTime == 0) {
            dividendsInfo_.lastUpdateTime = _currentBlockTimestamp();
        }
        // initialize cycleDividendsPercent to the minimum if never set before
        if (dividendsInfo_.cycleDividendsPercent == 0) {
            dividendsInfo_.cycleDividendsPercent = DEFAULT_CYCLE_DIVIDENDS_PERCENT;
        }
        dividendsInfo_.distributionDisabled = false;
        _distributedTokens.add(token);
        emit DistributedTokenEnabled(token);
    }

    /**
     * @dev Disables distribution of a given token as dividends
     *
     * Effective from the next cycle
     */
    function disableDistributedToken(address token) external onlyGuardianOrGovernor {
        DividendsInfo storage dividendsInfo_ = dividendsInfo[token];
        require(
            dividendsInfo_.lastUpdateTime > 0 && !dividendsInfo_.distributionDisabled,
            "disableDistributedToken: Already disabled dividends token"
        );
        dividendsInfo_.distributionDisabled = true;
        emit DistributedTokenDisabled(token);
    }

    /**
     * @dev Updates the percentage of pending dividends that will be distributed during the next cycle
     *
     * Must be a value between MIN_CYCLE_DIVIDENDS_PERCENT and MAX_CYCLE_DIVIDENDS_PERCENT
     */
    function updateCycleDividendsPercent(address token, uint256 percent) external onlyGuardianOrGovernor {
        require(percent <= MAX_CYCLE_DIVIDENDS_PERCENT, "updateCycleDividendsPercent: percent mustn't exceed maximum");
        require(percent >= MIN_CYCLE_DIVIDENDS_PERCENT, "updateCycleDividendsPercent: percent mustn't exceed minimum");
        DividendsInfo storage dividendsInfo_ = dividendsInfo[token];
        uint256 previousPercent = dividendsInfo_.cycleDividendsPercent;
        dividendsInfo_.cycleDividendsPercent = percent;
        emit CycleDividendsPercentUpdated(token, previousPercent, dividendsInfo_.cycleDividendsPercent);
    }

    /**
     * @dev remove an address from _distributedTokens
     *
     * Can only be valid for a disabled dividends token and if the distribution has ended
     */
    function removeTokenFromDistributedTokens(address tokenToRemove) external onlyGuardianOrGovernor {
        DividendsInfo storage _dividendsInfo = dividendsInfo[tokenToRemove];
        require(
            _dividendsInfo.distributionDisabled && _dividendsInfo.currentDistributionAmount == 0,
            "removeTokenFromDistributedTokens: cannot be removed"
        );
        _distributedTokens.remove(tokenToRemove);
        emit DistributedTokenRemoved(tokenToRemove);
    }

    /********************************************************/
    /****************** INTERNAL FUNCTIONS ******************/
    /********************************************************/

    /**
     * @dev Returns the amount of dividends token distributed every second (times 1e2)
     */
    function _dividendsAmountPerSecond(address token) internal view returns (uint256) {
        if (!_distributedTokens.contains(token)) return 0;
        return dividendsInfo[token].currentDistributionAmount.mul(1e2).div(_cycleDurationSeconds);
    }

    /**
     * @dev Updates every user's rewards allocation for each distributed token
     */
    function _updateDividendsInfo(address token) internal {
        uint256 currentBlockTimestamp = _currentBlockTimestamp();
        DividendsInfo storage dividendsInfo_ = dividendsInfo[token];

        updateCurrentCycleStartTime();

        uint256 lastUpdateTime = dividendsInfo_.lastUpdateTime;
        uint256 accDividendsPerShare = dividendsInfo_.accDividendsPerShare;
        if (currentBlockTimestamp <= lastUpdateTime) {
            return;
        }

        // if no xZen is allocated or initial distribution has not started yet
        if (totalAllocation == 0 || currentBlockTimestamp < currentCycleStartTime) {
            dividendsInfo_.lastUpdateTime = currentBlockTimestamp;
            return;
        }

        uint256 currentDistributionAmount = dividendsInfo_.currentDistributionAmount; // gas saving
        uint256 currentCycleDistributedAmount = dividendsInfo_.currentCycleDistributedAmount; // gas saving

        // check if the current cycle has changed since last update
        if (lastUpdateTime < currentCycleStartTime) {
            // update accDividendPerShare for the end of the previous cycle
            accDividendsPerShare = accDividendsPerShare.add(
                (currentDistributionAmount.mul(1e2).sub(currentCycleDistributedAmount)).mul(1e16).div(totalAllocation)
            );

            // check if distribution is enabled
            if (!dividendsInfo_.distributionDisabled) {
                // transfer the token's cycleDividendsPercent part from the pending slot to the distribution slot
                dividendsInfo_.distributedAmount = dividendsInfo_.distributedAmount.add(currentDistributionAmount);

                uint256 pendingAmount = dividendsInfo_.pendingAmount;
                currentDistributionAmount = pendingAmount.mul(dividendsInfo_.cycleDividendsPercent).div(10000);
                dividendsInfo_.currentDistributionAmount = currentDistributionAmount;
                dividendsInfo_.pendingAmount = pendingAmount.sub(currentDistributionAmount);
            } else {
                // stop the token's distribution on next cycle
                dividendsInfo_.distributedAmount = dividendsInfo_.distributedAmount.add(currentDistributionAmount);
                currentDistributionAmount = 0;
                dividendsInfo_.currentDistributionAmount = 0;
            }

            currentCycleDistributedAmount = 0;
            lastUpdateTime = currentCycleStartTime;
        }

        uint256 toDistribute = (currentBlockTimestamp.sub(lastUpdateTime)).mul(_dividendsAmountPerSecond(token));
        // ensure that we can't distribute more than currentDistributionAmount (for instance w/ a > 24h service interruption)
        if (currentCycleDistributedAmount.add(toDistribute) > currentDistributionAmount.mul(1e2)) {
            toDistribute = currentDistributionAmount.mul(1e2).sub(currentCycleDistributedAmount);
        }

        dividendsInfo_.currentCycleDistributedAmount = currentCycleDistributedAmount.add(toDistribute);
        dividendsInfo_.accDividendsPerShare = accDividendsPerShare.add(toDistribute.mul(1e16).div(totalAllocation));
        dividendsInfo_.lastUpdateTime = currentBlockTimestamp;
    }

    /**
     * Updates "userAddress" user's and total allocations for each distributed token
     */
    function _updateUser(address userAddress, uint256 newUserAllocation, uint256 newTotalAllocation) internal {
        uint256 previousUserAllocation = usersAllocation[userAddress];

        // for each distributedToken
        uint256 length = _distributedTokens.length();
        for (uint256 index = 0; index < length; ++index) {
            address token = _distributedTokens.at(index);
            _updateDividendsInfo(token);

            UserInfo storage user = users[token][userAddress];
            uint256 accDividendsPerShare = dividendsInfo[token].accDividendsPerShare;

            uint256 pending = previousUserAllocation.mul(accDividendsPerShare).div(1e18).sub(user.rewardDebt);
            user.pendingDividends = user.pendingDividends.add(pending);
            user.rewardDebt = newUserAllocation.mul(accDividendsPerShare).div(1e18);
        }

        usersAllocation[userAddress] = newUserAllocation;
        totalAllocation = newTotalAllocation;

        emit UserUpdated(userAddress, previousUserAllocation, newUserAllocation);
    }

    /**
     * @dev Harvests msg.sender's pending dividends of a given token
     */
    function _harvestDividends(address token) internal {
        _updateDividendsInfo(token);

        UserInfo storage user = users[token][msg.sender];
        uint256 accDividendsPerShare = dividendsInfo[token].accDividendsPerShare;

        uint256 userXZenAllocation = usersAllocation[msg.sender];
        uint256 pending = user.pendingDividends.add(
            userXZenAllocation.mul(accDividendsPerShare).div(1e18).sub(user.rewardDebt)
        );

        user.pendingDividends = 0;
        user.rewardDebt = userXZenAllocation.mul(accDividendsPerShare).div(1e18);

        _safeTokenTransfer(IERC20(token), msg.sender, pending);
        emit DividendsCollected(msg.sender, token, pending);
    }

    /**
     * @dev Safe token transfer function, in case rounding error causes pool to not have enough tokens
     */
    function _safeTokenTransfer(IERC20 token, address to, uint256 amount) internal {
        if (amount > 0) {
            uint256 tokenBal = token.balanceOf(address(this));
            if (amount > tokenBal) {
                token.safeTransfer(to, tokenBal);
            } else {
                token.safeTransfer(to, amount);
            }
        }
    }

    /**
     * @dev Utility function to get the current block timestamp
     */
    function _currentBlockTimestamp() internal view virtual returns (uint256) {
        /* solhint-disable not-rely-on-time */
        return block.timestamp;
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/AccessControl.sol)

pragma solidity ^0.8.0;

import "./IAccessControl.sol";
import "../utils/Context.sol";
import "../utils/Strings.sol";
import "../utils/introspection/ERC165.sol";

/**
 * @dev Contract module that allows children to implement role-based access
 * control mechanisms. This is a lightweight version that doesn't allow enumerating role
 * members except through off-chain means by accessing the contract event logs. Some
 * applications may benefit from on-chain enumerability, for those cases see
 * {AccessControlEnumerable}.
 *
 * Roles are referred to by their `bytes32` identifier. These should be exposed
 * in the external API and be unique. The best way to achieve this is by
 * using `public constant` hash digests:
 *
 * ```solidity
 * bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
 * ```
 *
 * Roles can be used to represent a set of permissions. To restrict access to a
 * function call, use {hasRole}:
 *
 * ```solidity
 * function foo() public {
 *     require(hasRole(MY_ROLE, msg.sender));
 *     ...
 * }
 * ```
 *
 * Roles can be granted and revoked dynamically via the {grantRole} and
 * {revokeRole} functions. Each role has an associated admin role, and only
 * accounts that have a role's admin role can call {grantRole} and {revokeRole}.
 *
 * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
 * that only accounts with this role will be able to grant or revoke other
 * roles. More complex role relationships can be created by using
 * {_setRoleAdmin}.
 *
 * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
 * grant and revoke this role. Extra precautions should be taken to secure
 * accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules}
 * to enforce additional security measures for this role.
 */
abstract contract AccessControl is Context, IAccessControl, ERC165 {
    struct RoleData {
        mapping(address => bool) members;
        bytes32 adminRole;
    }

    mapping(bytes32 => RoleData) private _roles;

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

    /**
     * @dev Modifier that checks that an account has a specific role. Reverts
     * with a standardized message including the required role.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
     *
     * _Available since v4.1._
     */
    modifier onlyRole(bytes32 role) {
        _checkRole(role);
        _;
    }

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

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) public view virtual override returns (bool) {
        return _roles[role].members[account];
    }

    /**
     * @dev Revert with a standard message if `_msgSender()` is missing `role`.
     * Overriding this function changes the behavior of the {onlyRole} modifier.
     *
     * Format of the revert message is described in {_checkRole}.
     *
     * _Available since v4.6._
     */
    function _checkRole(bytes32 role) internal view virtual {
        _checkRole(role, _msgSender());
    }

    /**
     * @dev Revert with a standard message if `account` is missing `role`.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
     */
    function _checkRole(bytes32 role, address account) internal view virtual {
        if (!hasRole(role, account)) {
            revert(
                string(
                    abi.encodePacked(
                        "AccessControl: account ",
                        Strings.toHexString(account),
                        " is missing role ",
                        Strings.toHexString(uint256(role), 32)
                    )
                )
            );
        }
    }

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {
        return _roles[role].adminRole;
    }

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

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

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been revoked `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `account`.
     *
     * May emit a {RoleRevoked} event.
     */
    function renounceRole(bytes32 role, address account) public virtual override {
        require(account == _msgSender(), "AccessControl: can only renounce roles for self");

        _revokeRole(role, account);
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event. Note that unlike {grantRole}, this function doesn't perform any
     * checks on the calling account.
     *
     * May emit a {RoleGranted} event.
     *
     * [WARNING]
     * ====
     * This function should only be called from the constructor when setting
     * up the initial roles for the system.
     *
     * Using this function in any other way is effectively circumventing the admin
     * system imposed by {AccessControl}.
     * ====
     *
     * NOTE: This function is deprecated in favor of {_grantRole}.
     */
    function _setupRole(bytes32 role, address account) internal virtual {
        _grantRole(role, account);
    }

    /**
     * @dev Sets `adminRole` as ``role``'s admin role.
     *
     * Emits a {RoleAdminChanged} event.
     */
    function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
        bytes32 previousAdminRole = getRoleAdmin(role);
        _roles[role].adminRole = adminRole;
        emit RoleAdminChanged(role, previousAdminRole, adminRole);
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleGranted} event.
     */
    function _grantRole(bytes32 role, address account) internal virtual {
        if (!hasRole(role, account)) {
            _roles[role].members[account] = true;
            emit RoleGranted(role, account, _msgSender());
        }
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleRevoked} event.
     */
    function _revokeRole(bytes32 role, address account) internal virtual {
        if (hasRole(role, account)) {
            _roles[role].members[account] = false;
            emit RoleRevoked(role, account, _msgSender());
        }
    }
}

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)

pragma solidity ^0.8.0;

import "../utils/Context.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 Pausable is Context {
    /**
     * @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.
     */
    constructor() {
        _paused = false;
    }

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

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

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

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

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

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

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;

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

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

    uint256 private _status;

    constructor() {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be _NOT_ENTERED
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

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

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

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        return _status == _ENTERED;
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (token/ERC20/extensions/IERC20Permit.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 *
 * ==== Security Considerations
 *
 * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
 * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
 * considered as an intention to spend the allowance in any specific way. The second is that because permits have
 * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
 * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
 * generally recommended is:
 *
 * ```solidity
 * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
 *     try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
 *     doThing(..., value);
 * }
 *
 * function doThing(..., uint256 value) public {
 *     token.safeTransferFrom(msg.sender, address(this), value);
 *     ...
 * }
 * ```
 *
 * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
 * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
 * {SafeERC20-safeTransferFrom}).
 *
 * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
 * contracts should have entry points that don't rely on permit.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     *
     * CAUTION: See Security Considerations above.
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

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

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

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

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

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

    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

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

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

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

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

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

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../extensions/IERC20Permit.sol";
import "../../../utils/Address.sol";

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

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

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

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

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

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

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

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

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

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

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

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
        // and not revert is the subcall reverts.

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)

pragma solidity ^0.8.1;

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

        return account.code.length > 0;
    }

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

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

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

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

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

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

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

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

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

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

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

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

    function _revert(bytes memory returndata, string memory errorMessage) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert(errorMessage);
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (utils/Context.sol)

pragma solidity ^0.8.0;

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

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

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)

pragma solidity ^0.8.0;

import "./IERC165.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 ERC165 is IERC165 {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}

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

pragma solidity ^0.8.0;

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

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/SafeMath.sol)

pragma solidity ^0.8.0;

// CAUTION
// This version of SafeMath should only be used with Solidity 0.8 or later,
// because it relies on the compiler's built in overflow checks.

/**
 * @dev Wrappers over Solidity's arithmetic operations.
 *
 * NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
 * now has built in overflow checking.
 */
library SafeMath {
    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            uint256 c = a + b;
            if (c < a) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b > a) return (false, 0);
            return (true, a - b);
        }
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
            // benefit is lost if 'b' is also tested.
            // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
            if (a == 0) return (true, 0);
            uint256 c = a * b;
            if (c / a != b) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the division of two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a / b);
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a % b);
        }
    }

    /**
     * @dev Returns the addition of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     *
     * - Addition cannot overflow.
     */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        return a + b;
    }

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

    /**
     * @dev Returns the multiplication of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     *
     * - Multiplication cannot overflow.
     */
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        return a * b;
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator.
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        return a / b;
    }

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

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {trySub}.
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        unchecked {
            require(b <= a, errorMessage);
            return a - b;
        }
    }

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

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting with custom message when dividing by zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryMod}.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        unchecked {
            require(b > 0, errorMessage);
            return a % b;
        }
    }
}

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

pragma solidity ^0.8.0;

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

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

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

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol)

pragma solidity ^0.8.0;

import "./math/Math.sol";
import "./math/SignedMath.sol";

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

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

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

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

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

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

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.

pragma solidity ^0.8.0;

/**
 * @dev Library for managing
 * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
 * types.
 *
 * Sets have the following properties:
 *
 * - Elements are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Elements are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```solidity
 * contract Example {
 *     // Add the library methods
 *     using EnumerableSet for EnumerableSet.AddressSet;
 *
 *     // Declare a set state variable
 *     EnumerableSet.AddressSet private mySet;
 * }
 * ```
 *
 * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
 * and `uint256` (`UintSet`) are supported.
 *
 * [WARNING]
 * ====
 * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
 * unusable.
 * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
 *
 * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
 * array of EnumerableSet.
 * ====
 */
library EnumerableSet {
    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Set type with
    // bytes32 values.
    // The Set implementation uses private functions, and user-facing
    // implementations (such as AddressSet) are just wrappers around the
    // underlying Set.
    // This means that we can only create new EnumerableSets for types that fit
    // in bytes32.

    struct Set {
        // Storage of set values
        bytes32[] _values;
        // Position of the value in the `values` array, plus 1 because index 0
        // means a value is not in the set.
        mapping(bytes32 => uint256) _indexes;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function _add(Set storage set, bytes32 value) private returns (bool) {
        if (!_contains(set, value)) {
            set._values.push(value);
            // The value is stored at length-1, but we add 1 to all indexes
            // and use 0 as a sentinel value
            set._indexes[value] = set._values.length;
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function _remove(Set storage set, bytes32 value) private returns (bool) {
        // We read and store the value's index to prevent multiple reads from the same storage slot
        uint256 valueIndex = set._indexes[value];

        if (valueIndex != 0) {
            // Equivalent to contains(set, value)
            // To delete an element from the _values array in O(1), we swap the element to delete with the last one in
            // the array, and then remove the last element (sometimes called as 'swap and pop').
            // This modifies the order of the array, as noted in {at}.

            uint256 toDeleteIndex = valueIndex - 1;
            uint256 lastIndex = set._values.length - 1;

            if (lastIndex != toDeleteIndex) {
                bytes32 lastValue = set._values[lastIndex];

                // Move the last value to the index where the value to delete is
                set._values[toDeleteIndex] = lastValue;
                // Update the index for the moved value
                set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex
            }

            // Delete the slot where the moved value was stored
            set._values.pop();

            // Delete the index for the deleted slot
            delete set._indexes[value];

            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function _contains(Set storage set, bytes32 value) private view returns (bool) {
        return set._indexes[value] != 0;
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function _length(Set storage set) private view returns (uint256) {
        return set._values.length;
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function _at(Set storage set, uint256 index) private view returns (bytes32) {
        return set._values[index];
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function _values(Set storage set) private view returns (bytes32[] memory) {
        return set._values;
    }

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _add(set._inner, value);
    }

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

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

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

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
        return _at(set._inner, index);
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
        bytes32[] memory store = _values(set._inner);
        bytes32[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(AddressSet storage set, address value) internal returns (bool) {
        return _add(set._inner, bytes32(uint256(uint160(value))));
    }

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

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(AddressSet storage set, address value) internal view returns (bool) {
        return _contains(set._inner, bytes32(uint256(uint160(value))));
    }

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

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(AddressSet storage set, uint256 index) internal view returns (address) {
        return address(uint160(uint256(_at(set._inner, index))));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(AddressSet storage set) internal view returns (address[] memory) {
        bytes32[] memory store = _values(set._inner);
        address[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // UintSet

    struct UintSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(UintSet storage set, uint256 value) internal returns (bool) {
        return _add(set._inner, bytes32(value));
    }

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

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

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

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(UintSet storage set, uint256 index) internal view returns (uint256) {
        return uint256(_at(set._inner, index));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(UintSet storage set) internal view returns (uint256[] memory) {
        bytes32[] memory store = _values(set._inner);
        uint256[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }
}

// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.4;

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

/// @title CHI stablecoin interface
interface IChi is IERC20 {
    // ----------- Events -----------

    event Minting(address indexed _to, address indexed _minter, uint256 _amount);

    event Burning(address indexed _to, address indexed _burner, uint256 _amount);

    // ----------- State changing api -----------

    function burn(uint256 amount) external;

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

    // ----------- Burner only state changing api -----------

    function burnFrom(address account, uint256 amount) external;

    // ----------- Minter only state changing api -----------

    function mint(address account, uint256 amount) external;

}

// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.4;

import "./IPermissions.sol";
import "../chi/IChi.sol";

/// @title Core Interface
interface ICore is IPermissions {
    // ----------- Events -----------

    event ChiUpdate(address indexed _chi);
    event ZenUpdate(address indexed _zen);
    event ZenAllocation(address indexed _to, uint256 _amount);

    // ----------- Governor only state changing api -----------

    function init() external;

    // ----------- Governor only state changing api -----------

    function setChi(address token) external;

    function setZen(address token) external;

    function allocateZen(address to, uint256 amount) external;

    // ----------- Getters -----------

    function chi() external view returns (IChi);

    function zen() external view returns (IERC20);
}

// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.4;

import "@openzeppelin/contracts/access/AccessControl.sol";
import "./IPermissionsRead.sol";

/// @title Permissions interface

interface IPermissions is IAccessControl, IPermissionsRead {
    // ----------- Governor only state changing api -----------

    function createRole(bytes32 role, bytes32 adminRole) external;

    function grantMinter(address minter) external;

    function grantPCVController(address pcvController) external;

    function grantGovernor(address governor) external;

    function grantGuardian(address guardian) external;

    function revokeMinter(address minter) external;

    function revokePCVController(address pcvController) external;

    function revokeGovernor(address governor) external;

    function revokeGuardian(address guardian) external;

    // ----------- Revoker only state changing api -----------

    function revokeOverride(bytes32 role, address account) external;

    // ----------- Getters -----------

    function GUARDIAN_ROLE() external view returns (bytes32);

    function GOVERN_ROLE() external view returns (bytes32);

    function MINTER_ROLE() external view returns (bytes32);

    function PCV_CONTROLLER_ROLE() external view returns (bytes32);
}

// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.4;

/// @title Permissions Read interface
interface IPermissionsRead {
    // ----------- Getters -----------

    function isMinter(address _address) external view returns (bool);

    function isGovernor(address _address) external view returns (bool);

    function isGuardian(address _address) external view returns (bool);

    function isPCVController(address _address) external view returns (bool);
}

// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.4;

import "./ICoreRef.sol";
import "@openzeppelin/contracts/security/Pausable.sol";

/// @title A Reference to Core
/// @notice defines some modifiers and utilities around interacting with Core
abstract contract CoreRef is ICoreRef, Pausable {
    ICore private immutable _core;
    IChi private immutable _chi;
    IERC20 private immutable _zen;

    constructor(address coreAddress) {
        _core = ICore(coreAddress);

        _chi = ICore(coreAddress).chi();
        _zen = ICore(coreAddress).zen();
    }

    function _initialize(address) internal {} // no-op for backward compatibility

    modifier ifMinterSelf() {
        if (_core.isMinter(address(this))) {
            _;
        }
    }

    modifier onlyMinter() {
        require(_core.isMinter(msg.sender), "CoreRef: Caller is not a minter");
        _;
    }

    modifier onlyPCVController() {
        require(_core.isPCVController(msg.sender), "CoreRef: Caller is not a PCV controller");
        _;
    }

    modifier onlyGovernor() {
        require(_core.isGovernor(msg.sender), "CoreRef: Caller is not a governor");
        _;
    }

    modifier onlyGuardianOrGovernor() {
        require(
            _core.isGovernor(msg.sender) || _core.isGuardian(msg.sender),
            "CoreRef: Caller is not a guardian or governor"
        );
        _;
    }

    modifier onlyGuardianOrPCVController() {
        require(
            _core.isPCVController(msg.sender) || _core.isGuardian(msg.sender),
            "CoreRef: Caller is not a PCV controller or governor"
        );
        _;
    }

    // Named onlyZenRole to prevent collision with OZ onlyRole modifier
    modifier onlyZenRole(bytes32 role) {
        require(_core.hasRole(role, msg.sender), "UNAUTHORIZED");
        _;
    }

    // Modifiers to allow any combination of roles
    modifier hasAnyOfTwoRoles(bytes32 role1, bytes32 role2) {
        require(_core.hasRole(role1, msg.sender) || _core.hasRole(role2, msg.sender), "UNAUTHORIZED");
        _;
    }

    modifier hasAnyOfThreeRoles(
        bytes32 role1,
        bytes32 role2,
        bytes32 role3
    ) {
        require(
            _core.hasRole(role1, msg.sender) || _core.hasRole(role2, msg.sender) || _core.hasRole(role3, msg.sender),
            "UNAUTHORIZED"
        );
        _;
    }

    modifier hasAnyOfFourRoles(
        bytes32 role1,
        bytes32 role2,
        bytes32 role3,
        bytes32 role4
    ) {
        require(
            _core.hasRole(role1, msg.sender) ||
                _core.hasRole(role2, msg.sender) ||
                _core.hasRole(role3, msg.sender) ||
                _core.hasRole(role4, msg.sender),
            "UNAUTHORIZED"
        );
        _;
    }

    modifier hasAnyOfFiveRoles(
        bytes32 role1,
        bytes32 role2,
        bytes32 role3,
        bytes32 role4,
        bytes32 role5
    ) {
        require(
            _core.hasRole(role1, msg.sender) ||
                _core.hasRole(role2, msg.sender) ||
                _core.hasRole(role3, msg.sender) ||
                _core.hasRole(role4, msg.sender) ||
                _core.hasRole(role5, msg.sender),
            "UNAUTHORIZED"
        );
        _;
    }

    modifier hasAnyOfSixRoles(
        bytes32 role1,
        bytes32 role2,
        bytes32 role3,
        bytes32 role4,
        bytes32 role5,
        bytes32 role6
    ) {
        require(
            _core.hasRole(role1, msg.sender) ||
                _core.hasRole(role2, msg.sender) ||
                _core.hasRole(role3, msg.sender) ||
                _core.hasRole(role4, msg.sender) ||
                _core.hasRole(role5, msg.sender) ||
                _core.hasRole(role6, msg.sender),
            "UNAUTHORIZED"
        );
        _;
    }

    modifier onlyChi() {
        require(msg.sender == address(_chi), "CoreRef: Caller is not CHI");
        _;
    }

    /// @notice set pausable methods to paused
    function pause() public override onlyGuardianOrGovernor {
        _pause();
    }

    /// @notice set pausable methods to unpaused
    function unpause() public override onlyGuardianOrGovernor {
        _unpause();
    }

    /// @notice address of the Core contract referenced
    /// @return ICore implementation address
    function core() public view override returns (ICore) {
        return _core;
    }

    /// @notice address of the Chi contract referenced by Core
    /// @return IChi implementation address
    function chi() public view override returns (IChi) {
        return _chi;
    }

    /// @notice address of the Zen contract referenced by Core
    /// @return IERC20 implementation address
    function zen() public view override returns (IERC20) {
        return _zen;
    }

    /// @notice chi balance of contract
    /// @return chi amount held
    function chiBalance() public view override returns (uint256) {
        return _chi.balanceOf(address(this));
    }

    /// @notice zen balance of contract
    /// @return zen amount held
    function zenBalance() public view override returns (uint256) {
        return _zen.balanceOf(address(this));
    }

    function _burnChiHeld() internal {
        _chi.burn(chiBalance());
    }

    function _mintChi(address to, uint256 amount) internal virtual {
        if (amount != 0) {
            _chi.mint(to, amount);
        }
    }
}

// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.4;

import "../core/ICore.sol";

/// @title CoreRef interface
interface ICoreRef {
    // ----------- Events -----------

    event CoreUpdate(address indexed oldCore, address indexed newCore);

    // ----------- Governor or Guardian only state changing api -----------

    function pause() external;

    function unpause() external;

    // ----------- Getters -----------

    function core() external view returns (ICore);

    function chi() external view returns (IChi);

    function zen() external view returns (IERC20);

    function chiBalance() external view returns (uint256);

    function zenBalance() external view returns (uint256);
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface IDividendsV2 {
  function distributedTokensLength() external view returns (uint256);

  function distributedToken(uint256 index) external view returns (address);

  function isDistributedToken(address token) external view returns (bool);

  function addDividendsToPending(address token, uint256 amount) external;
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface IXZenTokenUsage {
    function allocate(address userAddress, uint256 amount, bytes calldata data) external;
    function deallocate(address userAddress, uint256 amount, bytes calldata data) external;
}

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

Contract Security Audit

Contract ABI

API
[{"inputs":[{"internalType":"address","name":"xZenToken_","type":"address"},{"internalType":"uint256","name":"startTime_","type":"uint256"},{"internalType":"address","name":"_core","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldCore","type":"address"},{"indexed":true,"internalType":"address","name":"newCore","type":"address"}],"name":"CoreUpdate","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"previousValue","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newValue","type":"uint256"}],"name":"CycleDividendsPercentUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"}],"name":"DistributedTokenDisabled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"}],"name":"DistributedTokenEnabled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"}],"name":"DistributedTokenRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"DividendsAddedToPending","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"DividendsCollected","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"previousBalance","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newBalance","type":"uint256"}],"name":"UserUpdated","type":"event"},{"inputs":[],"name":"DEFAULT_CYCLE_DIVIDENDS_PERCENT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_CYCLE_DIVIDENDS_PERCENT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_DISTRIBUTED_TOKENS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MIN_CYCLE_DIVIDENDS_PERCENT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"addDividendsToPending","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"userAddress","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"allocate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"chi","outputs":[{"internalType":"contract IChi","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"chiBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"core","outputs":[{"internalType":"contract ICore","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentCycleStartTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"cycleDurationSeconds","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"userAddress","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"deallocate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"disableDistributedToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"distributedToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"distributedTokensLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"dividendsInfo","outputs":[{"internalType":"uint256","name":"currentDistributionAmount","type":"uint256"},{"internalType":"uint256","name":"currentCycleDistributedAmount","type":"uint256"},{"internalType":"uint256","name":"pendingAmount","type":"uint256"},{"internalType":"uint256","name":"distributedAmount","type":"uint256"},{"internalType":"uint256","name":"accDividendsPerShare","type":"uint256"},{"internalType":"uint256","name":"lastUpdateTime","type":"uint256"},{"internalType":"uint256","name":"cycleDividendsPercent","type":"uint256"},{"internalType":"bool","name":"distributionDisabled","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"}],"name":"emergencyWithdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"emergencyWithdrawAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"enableDistributedToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"harvestAllDividends","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"harvestDividends","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"isDistributedToken","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"massUpdateDividendsInfo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"nextCycleStartTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"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":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"userAddress","type":"address"}],"name":"pendingDividendsAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"tokenToRemove","type":"address"}],"name":"removeTokenFromDistributedTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"totalAllocation","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"updateCurrentCycleStartTime","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"percent","type":"uint256"}],"name":"updateCycleDividendsPercent","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"updateDividendsInfo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"users","outputs":[{"internalType":"uint256","name":"pendingDividends","type":"uint256"},{"internalType":"uint256","name":"rewardDebt","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"usersAllocation","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"xZenToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"zen","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"zenBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]

61010060405262093a806008553480156200001957600080fd5b5060405162002da238038062002da28339810160408190526200003c91620001be565b6000805460ff191690556001600160a01b03811660808190526040805163324abb3160e21b8152905183929163c92aecc49160048083019260209291908290030181865afa15801562000093573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620000b9919062000206565b6001600160a01b031660a0816001600160a01b031681525050806001600160a01b031663c8290efd6040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000111573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000137919062000206565b6001600160a01b0390811660c05260018055841690506200018d5760405162461bcd60e51b815260206004820152600c60248201526b7a65726f206164647265737360a01b604482015260640160405180910390fd5b506001600160a01b0390911660e0526009556200022d565b6001600160a01b0381168114620001bb57600080fd5b50565b600080600060608486031215620001d457600080fd5b8351620001e181620001a5565b602085015160408601519194509250620001fb81620001a5565b809150509250925092565b6000602082840312156200021957600080fd5b81516200022681620001a5565b9392505050565b60805160a05160c05160e051612aaf620002f36000396000818161043f015281816105b00152610b5d0152600081816104b90152610eaa0152600081816104df0152611332015260008181610553015281816109f101528181610a7f01528181610c9201528181610d2001528181610f3801528181610fc601528181611072015281816111000152818161143c015281816114ca015281816115a201528181611630015281816117ab01528181611839015281816119c60152611a540152612aaf6000f3fe608060405234801561001057600080fd5b50600436106102325760003560e01c80638456cb5911610130578063c92aecc4116100b8578063de9d477e1161007c578063de9d477e14610523578063e895cca314610536578063eb141dcf14610549578063f2f4eb2614610551578063f494ec5a1461057757600080fd5b8063c92aecc4146104dd578063d2af0b9414610503578063d637ff831461050b578063dd19171914610513578063ddd48f471461051b57600080fd5b8063ab69d957116100ff578063ab69d95714610474578063b989185a1461047c578063bd394a8d1461048f578063c4d3e08314610497578063c8290efd146104b757600080fd5b80638456cb59146104325780638c1612181461043a578063911c935c146103fc57806393c563af1461046157600080fd5b80635726d26e116101be5780636e34b818116101825780636e34b818146103fc5780636ff1c9bc1461040557806379203dc414610418578063799fb9651461042157806380e4b65a1461042a57600080fd5b80635726d26e146102e65780635b2acf17146102ee5780635c975abb1461037f5780635d9b436a1461038a5780635e80536a146103b557600080fd5b80633999a4e5116102055780633999a4e5146102a857806339f7df5f146102bb5780633f4ba83a146102c357806347b32f28146102cb578063549230c9146102d357600080fd5b8063034d7fcb146102375780631c75e3691461025f5780632d9c97a41461027457806335d2506d14610295575b600080fd5b61024a610245366004612770565b61058a565b60405190151581526020015b60405180910390f35b61027261026d36600461278d565b61059d565b005b610287610282366004612816565b610650565b604051908152602001610256565b6102726102a3366004612770565b6107a9565b6102726102b636600461284f565b610827565b610272610993565b6102726109dc565b610272610b16565b6102726102e136600461278d565b610b4a565b610272610bd6565b6103426102fc366004612770565b6004602081905260009182526040909120805460018201546002830154600384015494840154600585015460068601546007909601549496939592949192909160ff1688565b604080519889526020890197909752958701949094526060860192909252608085015260a084015260c0830152151560e082015261010001610256565b60005460ff1661024a565b61039d61039836600461287b565b610bf2565b6040516001600160a01b039091168152602001610256565b6103e76103c3366004612816565b60056020908152600092835260408084209091529082529020805460019091015482565b60408051928352602083019190915201610256565b61028761271081565b610272610413366004612770565b610c75565b61028760075481565b61028760095481565b610287610e92565b610272610f23565b61039d7f000000000000000000000000000000000000000000000000000000000000000081565b61027261046f366004612770565b61105d565b61028761131a565b61027261048a366004612770565b611369565b6102876113fa565b6102876104a5366004612770565b60066020526000908152604090205481565b7f000000000000000000000000000000000000000000000000000000000000000061039d565b7f000000000000000000000000000000000000000000000000000000000000000061039d565b610287600a81565b610287611406565b61027261141f565b600854610287565b610272610531366004612770565b61158d565b610272610544366004612770565b611796565b610287600181565b7f000000000000000000000000000000000000000000000000000000000000000061039d565b61027261058536600461284f565b6119b1565b6000610597600283611c41565b92915050565b6105a5611c63565b336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146105f65760405162461bcd60e51b81526004016105ed90612894565b60405180910390fd5b6001600160a01b0384166000908152600660205260408120546106199085611cbc565b9050600061063285600754611cbc90919063ffffffff16565b905061063f868383611cc8565b505061064a60018055565b50505050565b600060075460000361066457506000610597565b6001600160a01b03831660009081526004602081905260408220908101546005820154919290919061069587611e07565b905061069f611406565b421115610718576106e36106dc6007546106d6662386f26fc100006106d0866106d0896106ca611406565b90611e4c565b90611e58565b90611e64565b8490611cbc565b92506106ed611406565b91506107156008546106d660646106d688600601548960020154611e5890919063ffffffff16565b90505b61073b6106dc6007546106d6662386f26fc100006106d0866106d0896106ca4290565b6001600160a01b038881166000908152600560209081526040808320938b16835292815282822080546001909101546006909252929091205492955061079e9261079891906106ca90670de0b6b3a7640000906106d6908a611e58565b90611cbc565b979650505050505050565b806107b5600282611c41565b61081a5760405162461bcd60e51b815260206004820152603060248201527f76616c69646174654469737472696275746564546f6b656e733a20746f6b656e60448201526f20646f6573206e6f742065786973747360801b60648201526084016105ed565b61082382611e70565b5050565b61082f611c63565b6040516370a0823160e01b81523060048201526000906001600160a01b038416906370a0823190602401602060405180830381865afa158015610876573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061089a91906128dd565b6001600160a01b03841660008181526004602052604090209192506108c19033308661200c565b6040516370a0823160e01b81523060048201526000906109329084906001600160a01b038816906370a0823190602401602060405180830381865afa15801561090e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106ca91906128dd565b60028301549091506109449082611cbc565b60028301556040518181526001600160a01b038616907f28fd761b1b374f526d6eba05c1081e7547a7a6b978161fac6bded2f1dc7a99529060200160405180910390a250505061082360018055565b61099b611c63565b60006109a76002612077565b905060005b818110156109cf576109c76109c2600283612081565b61208d565b6001016109ac565b50506109da60018055565b565b604051631c86b03760e31b81523360048201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063e43581b890602401602060405180830381865afa158015610a40573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a6491906128f6565b80610af25750604051630c68ba2160e01b81523360048201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690630c68ba2190602401602060405180830381865afa158015610ace573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610af291906128f6565b610b0e5760405162461bcd60e51b81526004016105ed90612918565b6109da612175565b6000610b226002612077565b905060005b8181101561082357610b42610b3d600283612081565b611e70565b600101610b27565b610b52611c63565b336001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614610b9a5760405162461bcd60e51b81526004016105ed90612894565b6001600160a01b038416600090815260066020526040812054610bbd9085611e4c565b9050600061063285600754611e4c90919063ffffffff16565b6000610be0611406565b9050804210610bef5760098190555b50565b600081610bff6002612077565b8110610c635760405162461bcd60e51b815260206004820152602d60248201527f76616c69646174654469737472696275746564546f6b656e73496e6465783a2060448201526c696e646578206578697374733f60981b60648201526084016105ed565b610c6e600284612081565b9392505050565b610c7d611c63565b604051631c86b03760e31b81523360048201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063e43581b890602401602060405180830381865afa158015610ce1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d0591906128f6565b80610d935750604051630c68ba2160e01b81523360048201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690630c68ba2190602401602060405180830381865afa158015610d6f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d9391906128f6565b610daf5760405162461bcd60e51b81526004016105ed90612918565b6040516370a0823160e01b81523060048201526000906001600160a01b038316906370a0823190602401602060405180830381865afa158015610df6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e1a91906128dd565b905060008111610e7d5760405162461bcd60e51b815260206004820152602860248201527f656d657267656e637957697468647261773a20746f6b656e2062616c616e6365604482015267081a5cc81b9d5b1b60c21b60648201526084016105ed565b610e888233836121c7565b50610bef60018055565b6040516370a0823160e01b81523060048201526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906370a08231906024015b602060405180830381865afa158015610efa573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f1e91906128dd565b905090565b604051631c86b03760e31b81523360048201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063e43581b890602401602060405180830381865afa158015610f87573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fab91906128f6565b806110395750604051630c68ba2160e01b81523360048201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690630c68ba2190602401602060405180830381865afa158015611015573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061103991906128f6565b6110555760405162461bcd60e51b81526004016105ed90612918565b6109da612274565b604051631c86b03760e31b81523360048201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063e43581b890602401602060405180830381865afa1580156110c1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110e591906128f6565b806111735750604051630c68ba2160e01b81523360048201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690630c68ba2190602401602060405180830381865afa15801561114f573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061117391906128f6565b61118f5760405162461bcd60e51b81526004016105ed90612918565b6001600160a01b0381166000908152600460205260409020600581015415806111bc5750600781015460ff165b61122e5760405162461bcd60e51b815260206004820152603760248201527f656e61626c654469737472696275746564546f6b656e3a20416c72656164792060448201527f656e61626c6564206469766964656e647320746f6b656e00000000000000000060648201526084016105ed565b600a61123a6002612077565b106112a25760405162461bcd60e51b815260206004820152603260248201527f656e61626c654469737472696275746564546f6b656e3a20746f6f206d616e79604482015271206469737472696275746564546f6b656e7360701b60648201526084016105ed565b80600501546000036112b5574260058201555b80600601546000036112ca5761271060068201555b60078101805460ff191690556112e16002836122b1565b506040516001600160a01b038316907fefa645a0ab6703d2f2e7f177f50d16c90ce1c71e317bb91cbbdab430e0a3968290600090a25050565b6040516370a0823160e01b81523060048201526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906370a0823190602401610edd565b611371611c63565b61137c600282611c41565b6113e8576001600160a01b0381166000908152600460205260409020600301546113e85760405162461bcd60e51b815260206004820152601f60248201527f686172766573744469766964656e64733a20696e76616c696420746f6b656e0060448201526064016105ed565b6113f18161208d565b610bef60018055565b6000610f1e6002612077565b6000610f1e600854600954611cbc90919063ffffffff16565b611427611c63565b604051631c86b03760e31b81523360048201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063e43581b890602401602060405180830381865afa15801561148b573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114af91906128f6565b8061153d5750604051630c68ba2160e01b81523360048201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690630c68ba2190602401602060405180830381865afa158015611519573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061153d91906128f6565b6115595760405162461bcd60e51b81526004016105ed90612918565b60005b6115666002612077565b8110156115835761157b610413600283612081565b60010161155c565b506109da60018055565b604051631c86b03760e31b81523360048201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063e43581b890602401602060405180830381865afa1580156115f1573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061161591906128f6565b806116a35750604051630c68ba2160e01b81523360048201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690630c68ba2190602401602060405180830381865afa15801561167f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116a391906128f6565b6116bf5760405162461bcd60e51b81526004016105ed90612918565b6001600160a01b0381166000908152600460205260409020600781015460ff1680156116ea57508054155b6117525760405162461bcd60e51b815260206004820152603360248201527f72656d6f7665546f6b656e46726f6d4469737472696275746564546f6b656e736044820152720e8818d85b9b9bdd081899481c995b5bdd9959606a1b60648201526084016105ed565b61175d6002836122c6565b506040516001600160a01b038316907f17cd3cc84c669de8c5c4218fd1d9814e647b547d1e7f59287ea6989aa4e032c290600090a25050565b604051631c86b03760e31b81523360048201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063e43581b890602401602060405180830381865afa1580156117fa573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061181e91906128f6565b806118ac5750604051630c68ba2160e01b81523360048201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690630c68ba2190602401602060405180830381865afa158015611888573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118ac91906128f6565b6118c85760405162461bcd60e51b81526004016105ed90612918565b6001600160a01b03811660009081526004602052604090206005810154158015906118f85750600781015460ff16155b61196a5760405162461bcd60e51b815260206004820152603960248201527f64697361626c654469737472696275746564546f6b656e3a20416c726561647960448201527f2064697361626c6564206469766964656e647320746f6b656e0000000000000060648201526084016105ed565b60078101805460ff191660011790556040516001600160a01b038316907f961f10509197d967c55f8720c2b6a80d48433ef36db1b12cf3bf6bcf66da434690600090a25050565b604051631c86b03760e31b81523360048201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063e43581b890602401602060405180830381865afa158015611a15573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a3991906128f6565b80611ac75750604051630c68ba2160e01b81523360048201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690630c68ba2190602401602060405180830381865afa158015611aa3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ac791906128f6565b611ae35760405162461bcd60e51b81526004016105ed90612918565b612710811115611b5b5760405162461bcd60e51b815260206004820152603b60248201527f7570646174654379636c654469766964656e647350657263656e743a2070657260448201527f63656e74206d7573746e277420657863656564206d6178696d756d000000000060648201526084016105ed565b6001811015611bd25760405162461bcd60e51b815260206004820152603b60248201527f7570646174654379636c654469766964656e647350657263656e743a2070657260448201527f63656e74206d7573746e277420657863656564206d696e696d756d000000000060648201526084016105ed565b6001600160a01b038216600081815260046020526040908190206006810180549085905591519092907f82ebda75a31dc518c1b711aab73005a4dddecaf297cee2cf545e72b6a799eb5190611c339084908790918252602082015260400190565b60405180910390a250505050565b6001600160a01b03811660009081526001830160205260408120541515610c6e565b600260015403611cb55760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016105ed565b6002600155565b6000610c6e828461297b565b6001600160a01b03831660009081526006602052604081205490611cec6002612077565b905060005b81811015611da5576000611d06600283612081565b9050611d1181611e70565b6001600160a01b038082166000818152600560209081526040808320948c16835293815283822092825260049081905292812090920154600182015491929091611d6b906106ca670de0b6b3a76400006106d68b87611e58565b8354909150611d7a9082611cbc565b8355611d92670de0b6b3a76400006106d68b85611e58565b6001938401555050919091019050611cf1565b506001600160a01b038516600081815260066020908152604091829020879055600786905581518581529081018790527f97ce9d7086176d6da45e4e7999788176e2629a7591ffe505b0c1b13fe8052cc6910160405180910390a25050505050565b6000611e14600283611c41565b611e2057506000919050565b6008546001600160a01b03831660009081526004602052604090205461059791906106d6906064611e58565b6000610c6e828461298e565b6000610c6e82846129a1565b6000610c6e82846129b8565b6001600160a01b03811660009081526004602052604090204290611e92610bd6565b60058101546004820154818411611eaa575050505050565b6007541580611eba575060095484105b15611ec85750506005015550565b82546001840154600954841015611f7d57600754611efe906106dc906106d6662386f26fc100006106d0866106ca896064611e58565b600786015490935060ff16611f58576003850154611f1c9083611cbc565b600386015560028501546006860154611f3e90612710906106d6908490611e58565b8087559250611f4d8184611e4c565b600287015550611f74565b6003850154611f679083611cbc565b6003860155600080865591505b50600954925060005b6000611f95611f8b89611e07565b6106d08988611e4c565b9050611fa2836064611e58565b611fac8383611cbc565b1115611fc457611fc1826106ca856064611e58565b90505b611fce8282611cbc565b6001870155600754611ff690611fef906106d684662386f26fc10000611e58565b8590611cbc565b6004870155505050506005909101919091555050565b6040516001600160a01b038085166024830152831660448201526064810182905261064a9085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526122db565b6000610597825490565b6000610c6e83836123b0565b61209681611e70565b6001600160a01b038116600081815260056020908152604080832033808552908352818420948452600480845282852001549084526006909252822054600184015491929091612102906120fa906106ca670de0b6b3a76400006106d68789611e58565b855490611cbc565b60008555905061211e670de0b6b3a76400006106d68486611e58565b600185015561212e8533836121c7565b6040518181526001600160a01b0386169033907f45a4759e6c135135eaba72e35bf196d59fd6fe17e1772d731f05dc25ec5a96a29060200160405180910390a35050505050565b61217d6123da565b6000805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b801561226f576040516370a0823160e01b81523060048201526000906001600160a01b038516906370a0823190602401602060405180830381865afa158015612214573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061223891906128dd565b90508082111561225b576122566001600160a01b0385168483612423565b61064a565b61064a6001600160a01b0385168484612423565b505050565b61227c612453565b6000805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586121aa3390565b6000610c6e836001600160a01b038416612499565b6000610c6e836001600160a01b0384166124e8565b6000612330826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166125db9092919063ffffffff16565b905080516000148061235157508080602001905181019061235191906128f6565b61226f5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016105ed565b60008260000182815481106123c7576123c76129da565b9060005260206000200154905092915050565b60005460ff166109da5760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b60448201526064016105ed565b6040516001600160a01b03831660248201526044810182905261226f90849063a9059cbb60e01b90606401612040565b60005460ff16156109da5760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b60448201526064016105ed565b60008181526001830160205260408120546124e057508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610597565b506000610597565b600081815260018301602052604081205480156125d157600061250c60018361298e565b85549091506000906125209060019061298e565b9050818114612585576000866000018281548110612540576125406129da565b9060005260206000200154905080876000018481548110612563576125636129da565b6000918252602080832090910192909255918252600188019052604090208390555b8554869080612596576125966129f0565b600190038181906000526020600020016000905590558560010160008681526020019081526020016000206000905560019350505050610597565b6000915050610597565b60606125ea84846000856125f2565b949350505050565b6060824710156126535760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b60648201526084016105ed565b600080866001600160a01b0316858760405161266f9190612a2a565b60006040518083038185875af1925050503d80600081146126ac576040519150601f19603f3d011682016040523d82523d6000602084013e6126b1565b606091505b509150915061079e878383876060831561272c578251600003612725576001600160a01b0385163b6127255760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016105ed565b50816125ea565b6125ea83838151156127415781518083602001fd5b8060405162461bcd60e51b81526004016105ed9190612a46565b6001600160a01b0381168114610bef57600080fd5b60006020828403121561278257600080fd5b8135610c6e8161275b565b600080600080606085870312156127a357600080fd5b84356127ae8161275b565b935060208501359250604085013567ffffffffffffffff808211156127d257600080fd5b818701915087601f8301126127e657600080fd5b8135818111156127f557600080fd5b88602082850101111561280757600080fd5b95989497505060200194505050565b6000806040838503121561282957600080fd5b82356128348161275b565b915060208301356128448161275b565b809150509250929050565b6000806040838503121561286257600080fd5b823561286d8161275b565b946020939093013593505050565b60006020828403121561288d57600080fd5b5035919050565b60208082526029908201527f785a656e546f6b656e4f6e6c793a2063616c6c65722073686f756c64206265206040820152682c2d32b72a37b5b2b760b91b606082015260800190565b6000602082840312156128ef57600080fd5b5051919050565b60006020828403121561290857600080fd5b81518015158114610c6e57600080fd5b6020808252602d908201527f436f72655265663a2043616c6c6572206973206e6f742061206775617264696160408201526c371037b91033b7bb32b93737b960991b606082015260800190565b634e487b7160e01b600052601160045260246000fd5b8082018082111561059757610597612965565b8181038181111561059757610597612965565b808202811582820484141761059757610597612965565b6000826129d557634e487b7160e01b600052601260045260246000fd5b500490565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052603160045260246000fd5b60005b83811015612a21578181015183820152602001612a09565b50506000910152565b60008251612a3c818460208701612a06565b9190910192915050565b6020815260008251806020840152612a65816040850160208701612a06565b601f01601f1916919091016040019291505056fea2646970667358221220587bb42c40c5ddef02620758f50bb0f68a25bbe3e06453cd006b4ed0cf1eabfd64736f6c63430008180033000000000000000000000000b97cb8d98e5fa6a8f6f9dfb1eede9daedc3b7e5800000000000000000000000000000000000000000000000000000000663c1200000000000000000000000000463a02e3dfd1ca2a5bf90dc938b784ed1ea5d24c

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106102325760003560e01c80638456cb5911610130578063c92aecc4116100b8578063de9d477e1161007c578063de9d477e14610523578063e895cca314610536578063eb141dcf14610549578063f2f4eb2614610551578063f494ec5a1461057757600080fd5b8063c92aecc4146104dd578063d2af0b9414610503578063d637ff831461050b578063dd19171914610513578063ddd48f471461051b57600080fd5b8063ab69d957116100ff578063ab69d95714610474578063b989185a1461047c578063bd394a8d1461048f578063c4d3e08314610497578063c8290efd146104b757600080fd5b80638456cb59146104325780638c1612181461043a578063911c935c146103fc57806393c563af1461046157600080fd5b80635726d26e116101be5780636e34b818116101825780636e34b818146103fc5780636ff1c9bc1461040557806379203dc414610418578063799fb9651461042157806380e4b65a1461042a57600080fd5b80635726d26e146102e65780635b2acf17146102ee5780635c975abb1461037f5780635d9b436a1461038a5780635e80536a146103b557600080fd5b80633999a4e5116102055780633999a4e5146102a857806339f7df5f146102bb5780633f4ba83a146102c357806347b32f28146102cb578063549230c9146102d357600080fd5b8063034d7fcb146102375780631c75e3691461025f5780632d9c97a41461027457806335d2506d14610295575b600080fd5b61024a610245366004612770565b61058a565b60405190151581526020015b60405180910390f35b61027261026d36600461278d565b61059d565b005b610287610282366004612816565b610650565b604051908152602001610256565b6102726102a3366004612770565b6107a9565b6102726102b636600461284f565b610827565b610272610993565b6102726109dc565b610272610b16565b6102726102e136600461278d565b610b4a565b610272610bd6565b6103426102fc366004612770565b6004602081905260009182526040909120805460018201546002830154600384015494840154600585015460068601546007909601549496939592949192909160ff1688565b604080519889526020890197909752958701949094526060860192909252608085015260a084015260c0830152151560e082015261010001610256565b60005460ff1661024a565b61039d61039836600461287b565b610bf2565b6040516001600160a01b039091168152602001610256565b6103e76103c3366004612816565b60056020908152600092835260408084209091529082529020805460019091015482565b60408051928352602083019190915201610256565b61028761271081565b610272610413366004612770565b610c75565b61028760075481565b61028760095481565b610287610e92565b610272610f23565b61039d7f000000000000000000000000b97cb8d98e5fa6a8f6f9dfb1eede9daedc3b7e5881565b61027261046f366004612770565b61105d565b61028761131a565b61027261048a366004612770565b611369565b6102876113fa565b6102876104a5366004612770565b60066020526000908152604090205481565b7f000000000000000000000000188b158caf5ea252012dbd6030afc030329c496161039d565b7f0000000000000000000000002fc5cf65fd0a660801f119832b2158756968266d61039d565b610287600a81565b610287611406565b61027261141f565b600854610287565b610272610531366004612770565b61158d565b610272610544366004612770565b611796565b610287600181565b7f000000000000000000000000463a02e3dfd1ca2a5bf90dc938b784ed1ea5d24c61039d565b61027261058536600461284f565b6119b1565b6000610597600283611c41565b92915050565b6105a5611c63565b336001600160a01b037f000000000000000000000000b97cb8d98e5fa6a8f6f9dfb1eede9daedc3b7e5816146105f65760405162461bcd60e51b81526004016105ed90612894565b60405180910390fd5b6001600160a01b0384166000908152600660205260408120546106199085611cbc565b9050600061063285600754611cbc90919063ffffffff16565b905061063f868383611cc8565b505061064a60018055565b50505050565b600060075460000361066457506000610597565b6001600160a01b03831660009081526004602081905260408220908101546005820154919290919061069587611e07565b905061069f611406565b421115610718576106e36106dc6007546106d6662386f26fc100006106d0866106d0896106ca611406565b90611e4c565b90611e58565b90611e64565b8490611cbc565b92506106ed611406565b91506107156008546106d660646106d688600601548960020154611e5890919063ffffffff16565b90505b61073b6106dc6007546106d6662386f26fc100006106d0866106d0896106ca4290565b6001600160a01b038881166000908152600560209081526040808320938b16835292815282822080546001909101546006909252929091205492955061079e9261079891906106ca90670de0b6b3a7640000906106d6908a611e58565b90611cbc565b979650505050505050565b806107b5600282611c41565b61081a5760405162461bcd60e51b815260206004820152603060248201527f76616c69646174654469737472696275746564546f6b656e733a20746f6b656e60448201526f20646f6573206e6f742065786973747360801b60648201526084016105ed565b61082382611e70565b5050565b61082f611c63565b6040516370a0823160e01b81523060048201526000906001600160a01b038416906370a0823190602401602060405180830381865afa158015610876573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061089a91906128dd565b6001600160a01b03841660008181526004602052604090209192506108c19033308661200c565b6040516370a0823160e01b81523060048201526000906109329084906001600160a01b038816906370a0823190602401602060405180830381865afa15801561090e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106ca91906128dd565b60028301549091506109449082611cbc565b60028301556040518181526001600160a01b038616907f28fd761b1b374f526d6eba05c1081e7547a7a6b978161fac6bded2f1dc7a99529060200160405180910390a250505061082360018055565b61099b611c63565b60006109a76002612077565b905060005b818110156109cf576109c76109c2600283612081565b61208d565b6001016109ac565b50506109da60018055565b565b604051631c86b03760e31b81523360048201527f000000000000000000000000463a02e3dfd1ca2a5bf90dc938b784ed1ea5d24c6001600160a01b03169063e43581b890602401602060405180830381865afa158015610a40573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a6491906128f6565b80610af25750604051630c68ba2160e01b81523360048201527f000000000000000000000000463a02e3dfd1ca2a5bf90dc938b784ed1ea5d24c6001600160a01b031690630c68ba2190602401602060405180830381865afa158015610ace573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610af291906128f6565b610b0e5760405162461bcd60e51b81526004016105ed90612918565b6109da612175565b6000610b226002612077565b905060005b8181101561082357610b42610b3d600283612081565b611e70565b600101610b27565b610b52611c63565b336001600160a01b037f000000000000000000000000b97cb8d98e5fa6a8f6f9dfb1eede9daedc3b7e581614610b9a5760405162461bcd60e51b81526004016105ed90612894565b6001600160a01b038416600090815260066020526040812054610bbd9085611e4c565b9050600061063285600754611e4c90919063ffffffff16565b6000610be0611406565b9050804210610bef5760098190555b50565b600081610bff6002612077565b8110610c635760405162461bcd60e51b815260206004820152602d60248201527f76616c69646174654469737472696275746564546f6b656e73496e6465783a2060448201526c696e646578206578697374733f60981b60648201526084016105ed565b610c6e600284612081565b9392505050565b610c7d611c63565b604051631c86b03760e31b81523360048201527f000000000000000000000000463a02e3dfd1ca2a5bf90dc938b784ed1ea5d24c6001600160a01b03169063e43581b890602401602060405180830381865afa158015610ce1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d0591906128f6565b80610d935750604051630c68ba2160e01b81523360048201527f000000000000000000000000463a02e3dfd1ca2a5bf90dc938b784ed1ea5d24c6001600160a01b031690630c68ba2190602401602060405180830381865afa158015610d6f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d9391906128f6565b610daf5760405162461bcd60e51b81526004016105ed90612918565b6040516370a0823160e01b81523060048201526000906001600160a01b038316906370a0823190602401602060405180830381865afa158015610df6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e1a91906128dd565b905060008111610e7d5760405162461bcd60e51b815260206004820152602860248201527f656d657267656e637957697468647261773a20746f6b656e2062616c616e6365604482015267081a5cc81b9d5b1b60c21b60648201526084016105ed565b610e888233836121c7565b50610bef60018055565b6040516370a0823160e01b81523060048201526000907f000000000000000000000000188b158caf5ea252012dbd6030afc030329c49616001600160a01b0316906370a08231906024015b602060405180830381865afa158015610efa573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f1e91906128dd565b905090565b604051631c86b03760e31b81523360048201527f000000000000000000000000463a02e3dfd1ca2a5bf90dc938b784ed1ea5d24c6001600160a01b03169063e43581b890602401602060405180830381865afa158015610f87573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fab91906128f6565b806110395750604051630c68ba2160e01b81523360048201527f000000000000000000000000463a02e3dfd1ca2a5bf90dc938b784ed1ea5d24c6001600160a01b031690630c68ba2190602401602060405180830381865afa158015611015573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061103991906128f6565b6110555760405162461bcd60e51b81526004016105ed90612918565b6109da612274565b604051631c86b03760e31b81523360048201527f000000000000000000000000463a02e3dfd1ca2a5bf90dc938b784ed1ea5d24c6001600160a01b03169063e43581b890602401602060405180830381865afa1580156110c1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110e591906128f6565b806111735750604051630c68ba2160e01b81523360048201527f000000000000000000000000463a02e3dfd1ca2a5bf90dc938b784ed1ea5d24c6001600160a01b031690630c68ba2190602401602060405180830381865afa15801561114f573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061117391906128f6565b61118f5760405162461bcd60e51b81526004016105ed90612918565b6001600160a01b0381166000908152600460205260409020600581015415806111bc5750600781015460ff165b61122e5760405162461bcd60e51b815260206004820152603760248201527f656e61626c654469737472696275746564546f6b656e3a20416c72656164792060448201527f656e61626c6564206469766964656e647320746f6b656e00000000000000000060648201526084016105ed565b600a61123a6002612077565b106112a25760405162461bcd60e51b815260206004820152603260248201527f656e61626c654469737472696275746564546f6b656e3a20746f6f206d616e79604482015271206469737472696275746564546f6b656e7360701b60648201526084016105ed565b80600501546000036112b5574260058201555b80600601546000036112ca5761271060068201555b60078101805460ff191690556112e16002836122b1565b506040516001600160a01b038316907fefa645a0ab6703d2f2e7f177f50d16c90ce1c71e317bb91cbbdab430e0a3968290600090a25050565b6040516370a0823160e01b81523060048201526000907f0000000000000000000000002fc5cf65fd0a660801f119832b2158756968266d6001600160a01b0316906370a0823190602401610edd565b611371611c63565b61137c600282611c41565b6113e8576001600160a01b0381166000908152600460205260409020600301546113e85760405162461bcd60e51b815260206004820152601f60248201527f686172766573744469766964656e64733a20696e76616c696420746f6b656e0060448201526064016105ed565b6113f18161208d565b610bef60018055565b6000610f1e6002612077565b6000610f1e600854600954611cbc90919063ffffffff16565b611427611c63565b604051631c86b03760e31b81523360048201527f000000000000000000000000463a02e3dfd1ca2a5bf90dc938b784ed1ea5d24c6001600160a01b03169063e43581b890602401602060405180830381865afa15801561148b573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114af91906128f6565b8061153d5750604051630c68ba2160e01b81523360048201527f000000000000000000000000463a02e3dfd1ca2a5bf90dc938b784ed1ea5d24c6001600160a01b031690630c68ba2190602401602060405180830381865afa158015611519573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061153d91906128f6565b6115595760405162461bcd60e51b81526004016105ed90612918565b60005b6115666002612077565b8110156115835761157b610413600283612081565b60010161155c565b506109da60018055565b604051631c86b03760e31b81523360048201527f000000000000000000000000463a02e3dfd1ca2a5bf90dc938b784ed1ea5d24c6001600160a01b03169063e43581b890602401602060405180830381865afa1580156115f1573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061161591906128f6565b806116a35750604051630c68ba2160e01b81523360048201527f000000000000000000000000463a02e3dfd1ca2a5bf90dc938b784ed1ea5d24c6001600160a01b031690630c68ba2190602401602060405180830381865afa15801561167f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116a391906128f6565b6116bf5760405162461bcd60e51b81526004016105ed90612918565b6001600160a01b0381166000908152600460205260409020600781015460ff1680156116ea57508054155b6117525760405162461bcd60e51b815260206004820152603360248201527f72656d6f7665546f6b656e46726f6d4469737472696275746564546f6b656e736044820152720e8818d85b9b9bdd081899481c995b5bdd9959606a1b60648201526084016105ed565b61175d6002836122c6565b506040516001600160a01b038316907f17cd3cc84c669de8c5c4218fd1d9814e647b547d1e7f59287ea6989aa4e032c290600090a25050565b604051631c86b03760e31b81523360048201527f000000000000000000000000463a02e3dfd1ca2a5bf90dc938b784ed1ea5d24c6001600160a01b03169063e43581b890602401602060405180830381865afa1580156117fa573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061181e91906128f6565b806118ac5750604051630c68ba2160e01b81523360048201527f000000000000000000000000463a02e3dfd1ca2a5bf90dc938b784ed1ea5d24c6001600160a01b031690630c68ba2190602401602060405180830381865afa158015611888573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118ac91906128f6565b6118c85760405162461bcd60e51b81526004016105ed90612918565b6001600160a01b03811660009081526004602052604090206005810154158015906118f85750600781015460ff16155b61196a5760405162461bcd60e51b815260206004820152603960248201527f64697361626c654469737472696275746564546f6b656e3a20416c726561647960448201527f2064697361626c6564206469766964656e647320746f6b656e0000000000000060648201526084016105ed565b60078101805460ff191660011790556040516001600160a01b038316907f961f10509197d967c55f8720c2b6a80d48433ef36db1b12cf3bf6bcf66da434690600090a25050565b604051631c86b03760e31b81523360048201527f000000000000000000000000463a02e3dfd1ca2a5bf90dc938b784ed1ea5d24c6001600160a01b03169063e43581b890602401602060405180830381865afa158015611a15573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a3991906128f6565b80611ac75750604051630c68ba2160e01b81523360048201527f000000000000000000000000463a02e3dfd1ca2a5bf90dc938b784ed1ea5d24c6001600160a01b031690630c68ba2190602401602060405180830381865afa158015611aa3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ac791906128f6565b611ae35760405162461bcd60e51b81526004016105ed90612918565b612710811115611b5b5760405162461bcd60e51b815260206004820152603b60248201527f7570646174654379636c654469766964656e647350657263656e743a2070657260448201527f63656e74206d7573746e277420657863656564206d6178696d756d000000000060648201526084016105ed565b6001811015611bd25760405162461bcd60e51b815260206004820152603b60248201527f7570646174654379636c654469766964656e647350657263656e743a2070657260448201527f63656e74206d7573746e277420657863656564206d696e696d756d000000000060648201526084016105ed565b6001600160a01b038216600081815260046020526040908190206006810180549085905591519092907f82ebda75a31dc518c1b711aab73005a4dddecaf297cee2cf545e72b6a799eb5190611c339084908790918252602082015260400190565b60405180910390a250505050565b6001600160a01b03811660009081526001830160205260408120541515610c6e565b600260015403611cb55760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016105ed565b6002600155565b6000610c6e828461297b565b6001600160a01b03831660009081526006602052604081205490611cec6002612077565b905060005b81811015611da5576000611d06600283612081565b9050611d1181611e70565b6001600160a01b038082166000818152600560209081526040808320948c16835293815283822092825260049081905292812090920154600182015491929091611d6b906106ca670de0b6b3a76400006106d68b87611e58565b8354909150611d7a9082611cbc565b8355611d92670de0b6b3a76400006106d68b85611e58565b6001938401555050919091019050611cf1565b506001600160a01b038516600081815260066020908152604091829020879055600786905581518581529081018790527f97ce9d7086176d6da45e4e7999788176e2629a7591ffe505b0c1b13fe8052cc6910160405180910390a25050505050565b6000611e14600283611c41565b611e2057506000919050565b6008546001600160a01b03831660009081526004602052604090205461059791906106d6906064611e58565b6000610c6e828461298e565b6000610c6e82846129a1565b6000610c6e82846129b8565b6001600160a01b03811660009081526004602052604090204290611e92610bd6565b60058101546004820154818411611eaa575050505050565b6007541580611eba575060095484105b15611ec85750506005015550565b82546001840154600954841015611f7d57600754611efe906106dc906106d6662386f26fc100006106d0866106ca896064611e58565b600786015490935060ff16611f58576003850154611f1c9083611cbc565b600386015560028501546006860154611f3e90612710906106d6908490611e58565b8087559250611f4d8184611e4c565b600287015550611f74565b6003850154611f679083611cbc565b6003860155600080865591505b50600954925060005b6000611f95611f8b89611e07565b6106d08988611e4c565b9050611fa2836064611e58565b611fac8383611cbc565b1115611fc457611fc1826106ca856064611e58565b90505b611fce8282611cbc565b6001870155600754611ff690611fef906106d684662386f26fc10000611e58565b8590611cbc565b6004870155505050506005909101919091555050565b6040516001600160a01b038085166024830152831660448201526064810182905261064a9085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526122db565b6000610597825490565b6000610c6e83836123b0565b61209681611e70565b6001600160a01b038116600081815260056020908152604080832033808552908352818420948452600480845282852001549084526006909252822054600184015491929091612102906120fa906106ca670de0b6b3a76400006106d68789611e58565b855490611cbc565b60008555905061211e670de0b6b3a76400006106d68486611e58565b600185015561212e8533836121c7565b6040518181526001600160a01b0386169033907f45a4759e6c135135eaba72e35bf196d59fd6fe17e1772d731f05dc25ec5a96a29060200160405180910390a35050505050565b61217d6123da565b6000805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b801561226f576040516370a0823160e01b81523060048201526000906001600160a01b038516906370a0823190602401602060405180830381865afa158015612214573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061223891906128dd565b90508082111561225b576122566001600160a01b0385168483612423565b61064a565b61064a6001600160a01b0385168484612423565b505050565b61227c612453565b6000805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586121aa3390565b6000610c6e836001600160a01b038416612499565b6000610c6e836001600160a01b0384166124e8565b6000612330826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166125db9092919063ffffffff16565b905080516000148061235157508080602001905181019061235191906128f6565b61226f5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016105ed565b60008260000182815481106123c7576123c76129da565b9060005260206000200154905092915050565b60005460ff166109da5760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b60448201526064016105ed565b6040516001600160a01b03831660248201526044810182905261226f90849063a9059cbb60e01b90606401612040565b60005460ff16156109da5760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b60448201526064016105ed565b60008181526001830160205260408120546124e057508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610597565b506000610597565b600081815260018301602052604081205480156125d157600061250c60018361298e565b85549091506000906125209060019061298e565b9050818114612585576000866000018281548110612540576125406129da565b9060005260206000200154905080876000018481548110612563576125636129da565b6000918252602080832090910192909255918252600188019052604090208390555b8554869080612596576125966129f0565b600190038181906000526020600020016000905590558560010160008681526020019081526020016000206000905560019350505050610597565b6000915050610597565b60606125ea84846000856125f2565b949350505050565b6060824710156126535760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b60648201526084016105ed565b600080866001600160a01b0316858760405161266f9190612a2a565b60006040518083038185875af1925050503d80600081146126ac576040519150601f19603f3d011682016040523d82523d6000602084013e6126b1565b606091505b509150915061079e878383876060831561272c578251600003612725576001600160a01b0385163b6127255760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016105ed565b50816125ea565b6125ea83838151156127415781518083602001fd5b8060405162461bcd60e51b81526004016105ed9190612a46565b6001600160a01b0381168114610bef57600080fd5b60006020828403121561278257600080fd5b8135610c6e8161275b565b600080600080606085870312156127a357600080fd5b84356127ae8161275b565b935060208501359250604085013567ffffffffffffffff808211156127d257600080fd5b818701915087601f8301126127e657600080fd5b8135818111156127f557600080fd5b88602082850101111561280757600080fd5b95989497505060200194505050565b6000806040838503121561282957600080fd5b82356128348161275b565b915060208301356128448161275b565b809150509250929050565b6000806040838503121561286257600080fd5b823561286d8161275b565b946020939093013593505050565b60006020828403121561288d57600080fd5b5035919050565b60208082526029908201527f785a656e546f6b656e4f6e6c793a2063616c6c65722073686f756c64206265206040820152682c2d32b72a37b5b2b760b91b606082015260800190565b6000602082840312156128ef57600080fd5b5051919050565b60006020828403121561290857600080fd5b81518015158114610c6e57600080fd5b6020808252602d908201527f436f72655265663a2043616c6c6572206973206e6f742061206775617264696160408201526c371037b91033b7bb32b93737b960991b606082015260800190565b634e487b7160e01b600052601160045260246000fd5b8082018082111561059757610597612965565b8181038181111561059757610597612965565b808202811582820484141761059757610597612965565b6000826129d557634e487b7160e01b600052601260045260246000fd5b500490565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052603160045260246000fd5b60005b83811015612a21578181015183820152602001612a09565b50506000910152565b60008251612a3c818460208701612a06565b9190910192915050565b6020815260008251806020840152612a65816040850160208701612a06565b601f01601f1916919091016040019291505056fea2646970667358221220587bb42c40c5ddef02620758f50bb0f68a25bbe3e06453cd006b4ed0cf1eabfd64736f6c63430008180033

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

000000000000000000000000b97cb8d98e5fa6a8f6f9dfb1eede9daedc3b7e5800000000000000000000000000000000000000000000000000000000663c1200000000000000000000000000463a02e3dfd1ca2a5bf90dc938b784ed1ea5d24c

-----Decoded View---------------
Arg [0] : xZenToken_ (address): 0xb97CB8d98e5Fa6a8F6F9dfb1eEDe9DaEdC3B7E58
Arg [1] : startTime_ (uint256): 1715212800
Arg [2] : _core (address): 0x463a02e3dfD1CA2A5bF90Dc938B784eD1eA5D24C

-----Encoded View---------------
3 Constructor Arguments found :
Arg [0] : 000000000000000000000000b97cb8d98e5fa6a8f6f9dfb1eede9daedc3b7e58
Arg [1] : 00000000000000000000000000000000000000000000000000000000663c1200
Arg [2] : 000000000000000000000000463a02e3dfd1ca2a5bf90dc938b784ed1ea5d24c


Block Transaction Gas Used Reward
view all blocks sequenced

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

Validator Index Block Amount
View All Withdrawals

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

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