creation_sourcecode: {{
    "language": "Solidity",
    "sources": {
      "contracts/VTVLVesting.sol": {
        "content": "//SPDX-License-Identifier: Unlicense\npragma solidity 0.8.14;\n\nimport \"@openzeppelin/contracts/utils/Context.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"@openzeppelin/contracts/interfaces/IERC20.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\nimport \"@openzeppelin/contracts/security/ReentrancyGuard.sol\";\nimport \"./AccessProtected.sol\";\n\ncontract VTVLVesting is Context, AccessProtected, ReentrancyGuard {\n    using SafeERC20 for IERC20;\n\n    /**\n    @notice Address of the token that we're vesting\n     */\n    IERC20 public immutable tokenAddress;\n\n    /**\n    @notice How many tokens are already allocated to vesting schedules.\n    @dev Our balance of the token must always be greater than this amount.\n    * Otherwise we risk some users not getting their shares.\n    * This gets reduced as the users are paid out or when their schedules are revoked (as it is not reserved any more).\n    * In other words, this represents the amount the contract is scheduled to pay out at some point if the \n    * owner were to never interact with the contract.\n    */\n    uint256 public numTokensReservedForVesting = 0;\n\n    /**\n    @notice A structure representing a single claim - supporting linear and cliff vesting.\n     */\n    struct Claim {\n        // Using 40 bits for timestamp (seconds)\n        // Gives us a range from 1 Jan 1970 (Unix epoch) up to approximately 35 thousand years from then (2^40 / (365 * 24 * 60 * 60) ~= 35k)\n        uint40 startTimestamp; // When does the vesting start (40 bits is enough for TS)\n        uint40 endTimestamp; // When does the vesting end - the vesting goes linearly between the start and end timestamps\n        uint40 cliffReleaseTimestamp; // At which timestamp is the cliffAmount released. This must be <= startTimestamp\n        uint40 releaseIntervalSecs; // Every how many seconds does the vested amount increase.\n        // uint112 range: range 0 –     5,192,296,858,534,827,628,530,496,329,220,095.\n        // uint112 range: range 0 –                             5,192,296,858,534,827.\n        uint256 linearVestAmount; // total entitlement\n        uint256 amountWithdrawn; // how much was withdrawn thus far - released at the cliffReleaseTimestamp\n        uint112 cliffAmount; // how much is released at the cliff\n        bool isActive; // whether this claim is active (or revoked)\n        // should keep the current index of struct fields to avoid changing frontend code regarding this change\n        uint40 deactivationTimestamp;\n    }\n\n    // Mapping every user address to his/her Claim\n    // Only one Claim possible per address\n    mapping(address => Claim) internal claims;\n\n    // Track the recipients of the vesting\n    address[] internal vestingRecipients;\n\n    // Events:\n    /**\n    @notice Emitted when a founder adds a vesting schedule.\n     */\n    event ClaimCreated(address indexed _recipient, Claim _claim);\n\n    /**\n    @notice Emitted when someone withdraws a vested amount\n    */\n    event Claimed(address indexed _recipient, uint256 _withdrawalAmount);\n\n    /** \n    @notice Emitted when a claim is revoked\n    */\n    event ClaimRevoked(\n        address indexed _recipient,\n        uint256 _numTokensWithheld,\n        uint256 revocationTimestamp,\n        Claim _claim\n    );\n\n    /** \n    @notice Emitted when admin withdraws.\n    */\n    event AdminWithdrawn(address indexed _recipient, uint256 _amountRequested);\n\n    //\n    /**\n    @notice Construct the contract, taking the ERC20 token to be vested as the parameter.\n    @dev The owner can set the contract in question when creating the contract.\n     */\n    constructor(IERC20 _tokenAddress) {\n        require(address(_tokenAddress) != address(0), \"INVALID_ADDRESS\");\n        tokenAddress = _tokenAddress;\n    }\n\n    /**\n    @notice Basic getter for a claim. \n    @dev Could be using public claims var, but this is cleaner in terms of naming. (getClaim(address) as opposed to claims(address)). \n    @param _recipient - the address for which we fetch the claim.\n     */\n    function getClaim(address _recipient) external view returns (Claim memory) {\n        return claims[_recipient];\n    }\n\n    /**\n    @notice This modifier requires that an user has a claim attached.\n    @dev  To determine this, we check that a claim:\n    * - is active\n    * - start timestamp is nonzero.\n    * These are sufficient conditions because we only ever set startTimestamp in \n    * createClaim, and we never change it. Therefore, startTimestamp will be set\n    * IFF a claim has been created. In addition to that, we need to check\n    * a claim is active (since this is has_*Active*_Claim)\n    */\n    modifier hasActiveClaim(address _recipient) {\n        Claim storage _claim = claims[_recipient];\n        require(_claim.startTimestamp > 0, \"NO_ACTIVE_CLAIM\");\n\n        // We however still need the active check, since (due to the name of the function)\n        // we want to only allow active claims\n        require(_claim.isActive, \"NO_ACTIVE_CLAIM\");\n\n        // Save gas, omit further checks\n        // require(_claim.linearVestAmount + _claim.cliffAmount > 0, \"INVALID_VESTED_AMOUNT\");\n        // require(_claim.endTimestamp > 0, \"NO_END_TIMESTAMP\");\n        _;\n    }\n\n    /** \n    @notice Modifier which is opposite hasActiveClaim\n    @dev Requires that all fields are unset\n    */\n    modifier hasNoClaim(address _recipient) {\n        Claim storage _claim = claims[_recipient];\n        // Start timestamp != 0 is a sufficient condition for a claim to exist\n        // This is because we only ever add claims (or modify startTs) in the createClaim function\n        // Which requires that its input startTimestamp be nonzero\n        // So therefore, a zero value for this indicates the claim does not exist.\n        require(_claim.startTimestamp == 0, \"CLAIM_ALREADY_EXISTS\");\n\n        // We don't even need to check for active to be unset, since this function only\n        // determines that a claim hasn't been set\n        // require(_claim.isActive == false, \"CLAIM_ALREADY_EXISTS\");\n\n        // Further checks aren't necessary (to save gas), as they're done at creation time (createClaim)\n        // require(_claim.endTimestamp == 0, \"CLAIM_ALREADY_EXISTS\");\n        // require(_claim.linearVestAmount + _claim.cliffAmount == 0, \"CLAIM_ALREADY_EXISTS\");\n        // require(_claim.amountWithdrawn == 0, \"CLAIM_ALREADY_EXISTS\");\n        _;\n    }\n\n    /**\n    @notice Pure function to calculate the vested amount from a given _claim, at a reference timestamp\n    @param _claim The claim in question\n    @param _referenceTs Timestamp for which we're calculating\n     */\n    function _baseVestedAmount(Claim memory _claim, uint40 _referenceTs)\n        internal\n        pure\n        returns (uint256)\n    {\n        // If no schedule is created\n        if (!_claim.isActive && _claim.deactivationTimestamp == 0) {\n            return 0;\n        }\n\n        uint256 vestAmt = 0;\n\n        // Check if this time is over vesting end time\n        if (_referenceTs > _claim.endTimestamp) {\n            _referenceTs = _claim.endTimestamp;\n        }\n\n        // If we're past the cliffReleaseTimestamp, we release the cliffAmount\n        // We don't check here that cliffReleaseTimestamp is after the startTimestamp\n        if (_referenceTs >= _claim.cliffReleaseTimestamp) {\n            vestAmt += _claim.cliffAmount;\n        }\n\n        // Calculate the linearly vested amount - this is relevant only if we're past the schedule start\n        // at _referenceTs == _claim.startTimestamp, the period proportion will be 0 so we don't need to start the calc\n        if (_referenceTs > _claim.startTimestamp) {\n            uint40 currentVestingDurationSecs = _referenceTs -\n                _claim.startTimestamp; // How long since the start\n            \n            // Next, we need to calculated the duration truncated to nearest releaseIntervalSecs\n            uint40 truncatedCurrentVestingDurationSecs = (currentVestingDurationSecs /\n                    _claim.releaseIntervalSecs) *\n                    _claim.releaseIntervalSecs;\n\n            uint40 finalVestingDurationSecs = _claim.endTimestamp -\n                _claim.startTimestamp; // length of the interval\n\n            // Calculate the linear vested amount - fraction_of_interval_completed * linearVestedAmount\n            // Since fraction_of_interval_completed is truncatedCurrentVestingDurationSecs / finalVestingDurationSecs, the formula becomes\n            // truncatedCurrentVestingDurationSecs / finalVestingDurationSecs * linearVestAmount, so we can rewrite as below to avoid\n            // rounding errors\n            uint256 linearVestAmount = (_claim.linearVestAmount *\n                truncatedCurrentVestingDurationSecs) /\n                finalVestingDurationSecs;\n\n            // Having calculated the linearVestAmount, simply add it to the vested amount\n            vestAmt += linearVestAmount;\n        }\n\n        return vestAmt;\n    }\n\n    /**\n    @notice Calculate the amount vested for a given _recipient at a reference timestamp.\n    @param _recipient - The address for whom we're calculating\n    @param _referenceTs - The timestamp at which we want to calculate the vested amount.\n    @dev Simply call the _baseVestedAmount for the claim in question\n    */\n    function vestedAmount(address _recipient, uint40 _referenceTs)\n        public\n        view\n        returns (uint256)\n    {\n        Claim memory _claim = claims[_recipient];\n        uint40 vestEndTimestamp = _claim.isActive ? _referenceTs : _claim.deactivationTimestamp;\n        return _baseVestedAmount(_claim, vestEndTimestamp);\n    }\n\n    /**\n    @notice Calculate the total vested at the end of the schedule, by simply feeding in the end timestamp to the function above.\n    @dev This fn is somewhat superfluous, should probably be removed.\n    @param _recipient - The address for whom we're calculating\n     */\n    function finalVestedAmount(address _recipient)\n        public\n        view\n        returns (uint256)\n    {\n        Claim memory _claim = claims[_recipient];\n        return _baseVestedAmount(_claim, _claim.endTimestamp);\n    }\n\n    /**\n    @notice Calculates how much can we claim, by subtracting the already withdrawn amount from the vestedAmount at this moment.\n    @param _recipient - The address for whom we're calculating\n    */\n    function claimableAmount(address _recipient)\n        public\n        view\n        returns (uint256)\n    {\n        Claim memory _claim = claims[_recipient];\n        return vestedAmount(_recipient, uint40(block.timestamp)) - _claim.amountWithdrawn;\n    }\n\n    /**\n    @notice Calculates how much wil be possible to claim at the end of vesting date, by subtracting the already withdrawn\n            amount from the vestedAmount at this moment. Vesting date is either the end timestamp or the deactivation timestamp.\n    @param _recipient - The address for whom we're calculating\n    */\n    function finalClaimableAmount(address _recipient) external view returns (uint256) {\n        Claim storage _claim = claims[_recipient];\n        uint40 vestEndTimestamp = _claim.isActive ? _claim.endTimestamp : _claim.deactivationTimestamp;\n        return _baseVestedAmount(_claim, vestEndTimestamp) - _claim.amountWithdrawn;\n    }\n\n    /** \n    @notice Return all the addresses that have vesting schedules attached.\n    */\n    function allVestingRecipients() external view returns (address[] memory) {\n        return vestingRecipients;\n    }\n\n    /** \n    @notice Get the total number of vesting recipients.\n    */\n    function numVestingRecipients() external view returns (uint256) {\n        return vestingRecipients.length;\n    }\n\n    /** \n    @notice Permission-unchecked version of claim creation (no onlyAdmin). Actual logic for create claim, to be run within either createClaim or createClaimBatch.\n    @dev This'll simply check the input parameters, and create the structure verbatim based on passed in parameters.\n    @param _recipient - The address of the recipient of the schedule\n    @param _startTimestamp - The timestamp when the linear vesting starts\n    @param _endTimestamp - The timestamp when the linear vesting ends\n    @param _cliffReleaseTimestamp - The timestamp when the cliff is released (must be <= _startTimestamp, or 0 if no vesting)\n    @param _releaseIntervalSecs - The release interval for the linear vesting. If this is, for example, 60, that means that the linearly vested amount gets released every 60 seconds.\n    @param _linearVestAmount - The total amount to be linearly vested between _startTimestamp and _endTimestamp\n    @param _cliffAmount - The amount released at _cliffReleaseTimestamp. Can be 0 if _cliffReleaseTimestamp is also 0.\n     */\n    function _createClaimUnchecked(\n        address _recipient,\n        uint40 _startTimestamp,\n        uint40 _endTimestamp,\n        uint40 _cliffReleaseTimestamp,\n        uint40 _releaseIntervalSecs,\n        uint112 _linearVestAmount,\n        uint112 _cliffAmount\n    ) private hasNoClaim(_recipient) {\n        require(_recipient != address(0), \"INVALID_ADDRESS\");\n        require(_linearVestAmount + _cliffAmount > 0, \"INVALID_VESTED_AMOUNT\"); // Actually only one of linearvested/cliff amount must be 0, not necessarily both\n        require(_startTimestamp > 0, \"INVALID_START_TIMESTAMP\");\n        // Do we need to check whether _startTimestamp is greater than the current block.timestamp?\n        // Or do we allow schedules that started in the past?\n        // -> Conclusion: we want to allow this, for founders that might have forgotten to add some users, or to avoid issues with transactions not going through because of discoordination between block.timestamp and sender's local time\n        // require(_endTimestamp > 0, \"_endTimestamp must be valid\"); // not necessary because of the next condition (transitively)\n        require(_startTimestamp < _endTimestamp, \"INVALID_END_TIMESTAMP\"); // _endTimestamp must be after _startTimestamp\n        require(_releaseIntervalSecs > 0, \"INVALID_RELEASE_INTERVAL\");\n        require(\n            (_endTimestamp - _startTimestamp) % _releaseIntervalSecs == 0,\n            \"INVALID_INTERVAL_LENGTH\"\n        );\n\n        // Potential TODO: sanity check, if _linearVestAmount == 0, should we perhaps force that start and end ts are the same?\n\n        // No point in allowing cliff TS without the cliff amount or vice versa.\n        // Both or neither of _cliffReleaseTimestamp and _cliffAmount must be set. If cliff is set, _cliffReleaseTimestamp must be before or at the _startTimestamp\n        require(\n            (_cliffReleaseTimestamp > 0 &&\n                _cliffAmount > 0 &&\n                _cliffReleaseTimestamp <= _startTimestamp) ||\n                (_cliffReleaseTimestamp == 0 && _cliffAmount == 0),\n            \"INVALID_CLIFF\"\n        );\n\n        Claim storage _claim = claims[_recipient];\n        _claim.startTimestamp = _startTimestamp;\n        _claim.endTimestamp = _endTimestamp;\n        _claim.deactivationTimestamp = 0;\n        _claim.cliffReleaseTimestamp = _cliffReleaseTimestamp;\n        _claim.releaseIntervalSecs = _releaseIntervalSecs;\n        _claim.linearVestAmount = _linearVestAmount;\n        _claim.cliffAmount = _cliffAmount;\n        _claim.amountWithdrawn = 0;\n        _claim.isActive = true;\n\n        // Our total allocation is simply the full sum of the two amounts, _cliffAmount + _linearVestAmount\n        // Not necessary to use the more complex logic from _baseVestedAmount\n        uint256 allocatedAmount = _cliffAmount + _linearVestAmount;\n\n        // Still no effects up to this point (and tokenAddress is selected by contract deployer and is immutable), so no reentrancy risk\n        require(\n            tokenAddress.balanceOf(address(this)) >=\n                numTokensReservedForVesting + allocatedAmount,\n            \"INSUFFICIENT_BALANCE\"\n        );\n\n        // Done with checks\n\n        // Effects limited to lines below\n        numTokensReservedForVesting += allocatedAmount; // track the allocated amount\n        vestingRecipients.push(_recipient); // add the vesting recipient to the list\n        emit ClaimCreated(_recipient, _claim); // let everyone know\n    }\n\n    /** \n    @notice Create a claim based on the input parameters.\n    @dev This'll simply check the input parameters, and create the structure verbatim based on passed in parameters.\n    @param _recipient - The address of the recipient of the schedule\n    @param _startTimestamp - The timestamp when the linear vesting starts\n    @param _endTimestamp - The timestamp when the linear vesting ends\n    @param _cliffReleaseTimestamp - The timestamp when the cliff is released (must be <= _startTimestamp, or 0 if no vesting)\n    @param _releaseIntervalSecs - The release interval for the linear vesting. If this is, for example, 60, that means that the linearly vested amount gets released every 60 seconds.\n    @param _linearVestAmount - The total amount to be linearly vested between _startTimestamp and _endTimestamp\n    @param _cliffAmount - The amount released at _cliffReleaseTimestamp. Can be 0 if _cliffReleaseTimestamp is also 0.\n     */\n    function createClaim(\n        address _recipient,\n        uint40 _startTimestamp,\n        uint40 _endTimestamp,\n        uint40 _cliffReleaseTimestamp,\n        uint40 _releaseIntervalSecs,\n        uint112 _linearVestAmount,\n        uint112 _cliffAmount\n    ) external onlyAdmin {\n        _createClaimUnchecked(\n            _recipient,\n            _startTimestamp,\n            _endTimestamp,\n            _cliffReleaseTimestamp,\n            _releaseIntervalSecs,\n            _linearVestAmount,\n            _cliffAmount\n        );\n    }\n\n    /**\n    @notice The batch version of the createClaim function. Each argument is an array, and this function simply repeatedly calls the createClaim.\n    \n     */\n    function createClaimsBatch(\n        address[] memory _recipients,\n        uint40[] memory _startTimestamps,\n        uint40[] memory _endTimestamps,\n        uint40[] memory _cliffReleaseTimestamps,\n        uint40[] memory _releaseIntervalsSecs,\n        uint112[] memory _linearVestAmounts,\n        uint112[] memory _cliffAmounts\n    ) external onlyAdmin {\n        uint256 length = _recipients.length;\n        require(\n            _startTimestamps.length == length &&\n                _endTimestamps.length == length &&\n                _cliffReleaseTimestamps.length == length &&\n                _releaseIntervalsSecs.length == length &&\n                _linearVestAmounts.length == length &&\n                _cliffAmounts.length == length,\n            \"ARRAY_LENGTH_MISMATCH\"\n        );\n\n        for (uint256 i = 0; i < length; i++) {\n            _createClaimUnchecked(\n                _recipients[i],\n                _startTimestamps[i],\n                _endTimestamps[i],\n                _cliffReleaseTimestamps[i],\n                _releaseIntervalsSecs[i],\n                _linearVestAmounts[i],\n                _cliffAmounts[i]\n            );\n        }\n\n        // No need for separate emit, since createClaim will emit for each claim (and this function is merely a convenience/gas-saver for multiple claims creation)\n    }\n\n    /**\n    @notice Withdraw the full claimable balance.\n    @dev hasActiveClaim throws off anyone without a claim.\n     */\n    function withdraw() external hasActiveClaim(_msgSender()) nonReentrant {\n        // Get the message sender claim - if any\n\n        Claim storage usrClaim = claims[_msgSender()];\n\n        // we can use block.timestamp directly here as reference TS, as the function itself will make sure to cap it to endTimestamp\n        // Conversion of timestamp to uint40 should be safe since 48 bit allows for a lot of years.\n        uint256 allowance = vestedAmount(_msgSender(), uint40(block.timestamp));\n\n        // Make sure we didn't already withdraw more that we're allowed.\n        require(\n            allowance > usrClaim.amountWithdrawn && allowance > 0,\n            \"NOTHING_TO_WITHDRAW\"\n        );\n\n        // Calculate how much can we withdraw (equivalent to the above inequality)\n        uint256 amountRemaining = allowance - usrClaim.amountWithdrawn;\n        require(amountRemaining > 0, \"NOTHING_TO_WITHDRAW\");\n\n        // \"Double-entry bookkeeping\"\n        // Carry out the withdrawal by noting the withdrawn amount, and by transferring the tokens.\n        usrClaim.amountWithdrawn += amountRemaining;\n        // Reduce the allocated amount since the following transaction pays out so the \"debt\" gets reduced\n        numTokensReservedForVesting -= amountRemaining;\n\n        // After the \"books\" are set, transfer the tokens\n        // Reentrancy note - internal vars have been changed by now\n        // Also following Checks-effects-interactions pattern\n        tokenAddress.safeTransfer(_msgSender(), amountRemaining);\n\n        // Let withdrawal known to everyone.\n        emit Claimed(_msgSender(), amountRemaining);\n    }\n\n    /**\n    @notice Admin withdrawal of the unallocated tokens.\n    @param _amountRequested - the amount that we want to withdraw\n     */\n    function withdrawAdmin(uint256 _amountRequested)\n        public\n        onlyAdmin\n        nonReentrant\n    {\n        // Allow the owner to withdraw any balance not currently tied up in contracts.\n        uint256 amountRemaining = amountAvailableToWithdrawByAdmin();\n\n        require(amountRemaining >= _amountRequested, \"INSUFFICIENT_BALANCE\");\n\n        // Actually withdraw the tokens\n        // Reentrancy note - this operation doesn't touch any of the internal vars, simply transfers\n        // Also following Checks-effects-interactions pattern\n        tokenAddress.safeTransfer(_msgSender(), _amountRequested);\n\n        // Let the withdrawal known to everyone\n        emit AdminWithdrawn(_msgSender(), _amountRequested);\n    }\n\n    /** \n    @notice Allow an Owner to revoke a claim that is already active.\n    @dev The requirement is that a claim exists and that it's active.\n    */\n    function revokeClaim(address _recipient)\n        external\n        onlyAdmin\n        hasActiveClaim(_recipient)\n    {\n        // Fetch the claim\n        Claim storage _claim = claims[_recipient];\n\n        // Calculate what the claim should finally vest to\n        uint256 finalVestAmt = finalVestedAmount(_recipient);\n\n        // No point in revoking something that has been fully consumed\n        // so require that there be unconsumed amount\n        require(_claim.amountWithdrawn < finalVestAmt, \"NO_UNVESTED_AMOUNT\");\n\n        // Deactivate the claim, and release the appropriate amount of tokens\n        _claim.isActive = false; // This effectively reduces the liability by amountRemaining, so we can reduce the liability numTokensReservedForVesting by that much\n        _claim.deactivationTimestamp = uint40(block.timestamp);\n\n        // The amount that is \"reclaimed\" is equal to the total allocation less what was already withdrawn\n        uint256 vestedSoFarAmt = vestedAmount(_recipient, uint40(block.timestamp));\n        uint256 amountRemaining = finalVestAmt - vestedSoFarAmt;\n        numTokensReservedForVesting -= amountRemaining; // Reduces the allocation\n\n        // Tell everyone a claim has been revoked.\n        emit ClaimRevoked(\n            _recipient,\n            amountRemaining,\n            uint40(block.timestamp),\n            _claim\n        );\n    }\n\n    /**\n    @notice Withdraw a token which isn't controlled by the vesting contract.\n    @dev This contract controls/vests token at \"tokenAddress\". However, someone might send a different token. \n    To make sure these don't get accidentally trapped, give admin the ability to withdraw them (to their own address).\n    Note that the token to be withdrawn can't be the one at \"tokenAddress\".\n    @param _otherTokenAddress - the token which we want to withdraw\n     */\n    function withdrawOtherToken(IERC20 _otherTokenAddress)\n        external\n        onlyAdmin\n        nonReentrant\n    {\n        require(_otherTokenAddress != tokenAddress, \"INVALID_TOKEN\"); // tokenAddress address is already sure to be nonzero due to constructor\n        uint256 bal = _otherTokenAddress.balanceOf(address(this));\n        require(bal > 0, \"INSUFFICIENT_BALANCE\");\n        _otherTokenAddress.safeTransfer(_msgSender(), bal);\n    }\n\n    /**\n     * @notice Get amount that is not vested in contract\n     * @dev Whenever vesting is revoked, this amount will be increased.\n     */\n    function amountAvailableToWithdrawByAdmin() public view returns (uint256) {\n        return\n            tokenAddress.balanceOf(address(this)) - numTokensReservedForVesting;\n    }\n}\n"
      },
      "@openzeppelin/contracts/utils/Context.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n}\n"
      },
      "@openzeppelin/contracts/access/Ownable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract Ownable is Context {\n    address private _owner;\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the deployer as the initial owner.\n     */\n    constructor() {\n        _transferOwnership(_msgSender());\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n        _;\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions anymore. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby removing any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n}\n"
      },
      "@openzeppelin/contracts/interfaces/IERC20.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (interfaces/IERC20.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../token/ERC20/IERC20.sol\";\n"
      },
      "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20.sol\";\nimport \"../../../utils/Address.sol\";\n\n/**\n * @title SafeERC20\n * @dev Wrappers around ERC20 operations that throw on failure (when the token\n * contract returns false). Tokens that return no value (and instead revert or\n * throw on failure) are also supported, non-reverting calls are assumed to be\n * successful.\n * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,\n * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.\n */\nlibrary SafeERC20 {\n    using Address for address;\n\n    function safeTransfer(\n        IERC20 token,\n        address to,\n        uint256 value\n    ) internal {\n        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));\n    }\n\n    function safeTransferFrom(\n        IERC20 token,\n        address from,\n        address to,\n        uint256 value\n    ) internal {\n        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));\n    }\n\n    /**\n     * @dev Deprecated. This function has issues similar to the ones found in\n     * {IERC20-approve}, and its usage is discouraged.\n     *\n     * Whenever possible, use {safeIncreaseAllowance} and\n     * {safeDecreaseAllowance} instead.\n     */\n    function safeApprove(\n        IERC20 token,\n        address spender,\n        uint256 value\n    ) internal {\n        // safeApprove should only be called when setting an initial allowance,\n        // or when resetting it to zero. To increase and decrease it, use\n        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'\n        require(\n            (value == 0) || (token.allowance(address(this), spender) == 0),\n            \"SafeERC20: approve from non-zero to non-zero allowance\"\n        );\n        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));\n    }\n\n    function safeIncreaseAllowance(\n        IERC20 token,\n        address spender,\n        uint256 value\n    ) internal {\n        uint256 newAllowance = token.allowance(address(this), spender) + value;\n        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\n    }\n\n    function safeDecreaseAllowance(\n        IERC20 token,\n        address spender,\n        uint256 value\n    ) internal {\n        unchecked {\n            uint256 oldAllowance = token.allowance(address(this), spender);\n            require(oldAllowance >= value, \"SafeERC20: decreased allowance below zero\");\n            uint256 newAllowance = oldAllowance - value;\n            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\n        }\n    }\n\n    /**\n     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n     * on the return value: the return value is optional (but if data is returned, it must not be false).\n     * @param token The token targeted by the call.\n     * @param data The call data (encoded using abi.encode or one of its variants).\n     */\n    function _callOptionalReturn(IERC20 token, bytes memory data) private {\n        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since\n        // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that\n        // the target address contains contract code and also asserts for success in the low-level call.\n\n        bytes memory returndata = address(token).functionCall(data, \"SafeERC20: low-level call failed\");\n        if (returndata.length > 0) {\n            // Return data is optional\n            require(abi.decode(returndata, (bool)), \"SafeERC20: ERC20 operation did not succeed\");\n        }\n    }\n}\n"
      },
      "@openzeppelin/contracts/security/ReentrancyGuard.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Contract module that helps prevent reentrant calls to a function.\n *\n * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier\n * available, which can be applied to functions to make sure there are no nested\n * (reentrant) calls to them.\n *\n * Note that because there is a single `nonReentrant` guard, functions marked as\n * `nonReentrant` may not call one another. This can be worked around by making\n * those functions `private`, and then adding `external` `nonReentrant` entry\n * points to them.\n *\n * TIP: If you would like to learn more about reentrancy and alternative ways\n * to protect against it, check out our blog post\n * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\n */\nabstract contract ReentrancyGuard {\n    // Booleans are more expensive than uint256 or any type that takes up a full\n    // word because each write operation emits an extra SLOAD to first read the\n    // slot's contents, replace the bits taken up by the boolean, and then write\n    // back. This is the compiler's defense against contract upgrades and\n    // pointer aliasing, and it cannot be disabled.\n\n    // The values being non-zero value makes deployment a bit more expensive,\n    // but in exchange the refund on every call to nonReentrant will be lower in\n    // amount. Since refunds are capped to a percentage of the total\n    // transaction's gas, it is best to keep them low in cases like this one, to\n    // increase the likelihood of the full refund coming into effect.\n    uint256 private constant _NOT_ENTERED = 1;\n    uint256 private constant _ENTERED = 2;\n\n    uint256 private _status;\n\n    constructor() {\n        _status = _NOT_ENTERED;\n    }\n\n    /**\n     * @dev Prevents a contract from calling itself, directly or indirectly.\n     * Calling a `nonReentrant` function from another `nonReentrant`\n     * function is not supported. It is possible to prevent this from happening\n     * by making the `nonReentrant` function external, and making it call a\n     * `private` function that does the actual work.\n     */\n    modifier nonReentrant() {\n        // On the first call to nonReentrant, _notEntered will be true\n        require(_status != _ENTERED, \"ReentrancyGuard: reentrant call\");\n\n        // Any calls to nonReentrant after this point will fail\n        _status = _ENTERED;\n\n        _;\n\n        // By storing the original value once again, a refund is triggered (see\n        // https://eips.ethereum.org/EIPS/eip-2200)\n        _status = _NOT_ENTERED;\n    }\n}\n"
      },
      "contracts/AccessProtected.sol": {
        "content": "//SPDX-License-Identifier: Unlicense\npragma solidity 0.8.14;\n\nimport \"@openzeppelin/contracts/utils/Context.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\n\n/** \n@title Access Limiter to multiple owner-specified accounts.\n@dev Exposes the onlyAdmin modifier, which will revert (ADMIN_ACCESS_REQUIRED) if the caller is not the owner nor the admin.\n*/\nabstract contract AccessProtected is Context {\n    mapping(address => bool) private _admins; // user address => admin? mapping\n\n    event AdminAccessSet(address indexed _admin, bool _enabled);\n\n    constructor() {\n        _admins[_msgSender()] = true;\n        emit AdminAccessSet(_msgSender(), true);\n    }\n\n    /**\n     * Throws if called by any account that isn't an admin or an owner.\n     */\n    modifier onlyAdmin() {\n        require(_admins[_msgSender()], \"ADMIN_ACCESS_REQUIRED\");\n        _;\n    }\n\n    function isAdmin(address _addressToCheck) external view returns (bool) {\n        return _admins[_addressToCheck];\n    }\n\n    /**\n     * @notice Set/unset Admin Access for a given address.\n     *\n     * @param admin - Address of the new admin (or the one to be removed)\n     * @param isEnabled - Enable/Disable Admin Access\n     */\n    function setAdmin(address admin, bool isEnabled) public onlyAdmin {\n        require(admin != address(0), \"INVALID_ADDRESS\");\n        _admins[admin] = isEnabled;\n        emit AdminAccessSet(admin, isEnabled);\n    }\n}"
      },
      "@openzeppelin/contracts/token/ERC20/IERC20.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n    /**\n     * @dev Returns the amount of tokens in existence.\n     */\n    function totalSupply() external view returns (uint256);\n\n    /**\n     * @dev Returns the amount of tokens owned by `account`.\n     */\n    function balanceOf(address account) external view returns (uint256);\n\n    /**\n     * @dev Moves `amount` tokens from the caller's account to `to`.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transfer(address to, uint256 amount) external returns (bool);\n\n    /**\n     * @dev Returns the remaining number of tokens that `spender` will be\n     * allowed to spend on behalf of `owner` through {transferFrom}. This is\n     * zero by default.\n     *\n     * This value changes when {approve} or {transferFrom} are called.\n     */\n    function allowance(address owner, address spender) external view returns (uint256);\n\n    /**\n     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * IMPORTANT: Beware that changing an allowance with this method brings the risk\n     * that someone may use both the old and the new allowance by unfortunate\n     * transaction ordering. One possible solution to mitigate this race\n     * condition is to first reduce the spender's allowance to 0 and set the\n     * desired value afterwards:\n     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n     *\n     * Emits an {Approval} event.\n     */\n    function approve(address spender, uint256 amount) external returns (bool);\n\n    /**\n     * @dev Moves `amount` tokens from `from` to `to` using the\n     * allowance mechanism. `amount` is then deducted from the caller's\n     * allowance.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transferFrom(\n        address from,\n        address to,\n        uint256 amount\n    ) external returns (bool);\n\n    /**\n     * @dev Emitted when `value` tokens are moved from one account (`from`) to\n     * another (`to`).\n     *\n     * Note that `value` may be zero.\n     */\n    event Transfer(address indexed from, address indexed to, uint256 value);\n\n    /**\n     * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n     * a call to {approve}. `value` is the new allowance.\n     */\n    event Approval(address indexed owner, address indexed spender, uint256 value);\n}\n"
      },
      "@openzeppelin/contracts/utils/Address.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol)\n\npragma solidity ^0.8.1;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n    /**\n     * @dev Returns true if `account` is a contract.\n     *\n     * [IMPORTANT]\n     * ====\n     * It is unsafe to assume that an address for which this function returns\n     * false is an externally-owned account (EOA) and not a contract.\n     *\n     * Among others, `isContract` will return false for the following\n     * types of addresses:\n     *\n     *  - an externally-owned account\n     *  - a contract in construction\n     *  - an address where a contract will be created\n     *  - an address where a contract lived, but was destroyed\n     * ====\n     *\n     * [IMPORTANT]\n     * ====\n     * You shouldn't rely on `isContract` to protect against flash loan attacks!\n     *\n     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n     * constructor.\n     * ====\n     */\n    function isContract(address account) internal view returns (bool) {\n        // This method relies on extcodesize/address.code.length, which returns 0\n        // for contracts in construction, since the code is only stored at the end\n        // of the constructor execution.\n\n        return account.code.length > 0;\n    }\n\n    /**\n     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n     * `recipient`, forwarding all available gas and reverting on errors.\n     *\n     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n     * of certain opcodes, possibly making contracts go over the 2300 gas limit\n     * imposed by `transfer`, making them unable to receive funds via\n     * `transfer`. {sendValue} removes this limitation.\n     *\n     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n     *\n     * IMPORTANT: because control is transferred to `recipient`, care must be\n     * taken to not create reentrancy vulnerabilities. Consider using\n     * {ReentrancyGuard} or the\n     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n        (bool success, ) = recipient.call{value: amount}(\"\");\n        require(success, \"Address: unable to send value, recipient may have reverted\");\n    }\n\n    /**\n     * @dev Performs a Solidity function call using a low level `call`. A\n     * plain `call` is an unsafe replacement for a function call: use this\n     * function instead.\n     *\n     * If `target` reverts with a revert reason, it is bubbled up by this\n     * function (like regular Solidity function calls).\n     *\n     * Returns the raw returned data. To convert to the expected return value,\n     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n     *\n     * Requirements:\n     *\n     * - `target` must be a contract.\n     * - calling `target` with `data` must not revert.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionCall(target, data, \"Address: low-level call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n     * `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but also transferring `value` wei to `target`.\n     *\n     * Requirements:\n     *\n     * - the calling contract must have an ETH balance of at least `value`.\n     * - the called Solidity function must be `payable`.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n     * with `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        require(address(this).balance >= value, \"Address: insufficient balance for call\");\n        require(isContract(target), \"Address: call to non-contract\");\n\n        (bool success, bytes memory returndata) = target.call{value: value}(data);\n        return verifyCallResult(success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n        return functionStaticCall(target, data, \"Address: low-level static call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        require(isContract(target), \"Address: static call to non-contract\");\n\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return verifyCallResult(success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        require(isContract(target), \"Address: delegate call to non-contract\");\n\n        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return verifyCallResult(success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the\n     * revert reason using the provided one.\n     *\n     * _Available since v4.3._\n     */\n    function verifyCallResult(\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal pure returns (bytes memory) {\n        if (success) {\n            return returndata;\n        } else {\n            // Look for revert reason and bubble it up if present\n            if (returndata.length > 0) {\n                // The easiest way to bubble the revert reason is using memory via assembly\n\n                assembly {\n                    let returndata_size := mload(returndata)\n                    revert(add(32, returndata), returndata_size)\n                }\n            } else {\n                revert(errorMessage);\n            }\n        }\n    }\n}\n"
      }
    },
    "settings": {
      "optimizer": {
        "enabled": true,
        "runs": 200
      },
      "outputSelection": {
        "*": {
          "*": [
            "evm.bytecode",
            "evm.deployedBytecode",
            "devdoc",
            "userdoc",
            "metadata",
            "abi"
          ]
        }
      },
      "libraries": {}
    }
  }}