creation_sourcecode: {{
    "language": "Solidity",
    "sources": {
      "/Users/filipemsoccol/Documents/doiim/otogo-smart-contracts/contracts/launchpool.sol": {
        "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.4;\n\nimport \"../node_modules/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol\";\nimport \"../node_modules/@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\nimport \"../node_modules/@openzeppelin/contracts/token/ERC20/IERC20.sol\";\n\ninterface ITokenDecimals {\n    function decimals() external view returns (uint8);\n}\n\ninterface InterfaceCurve {\n    function getShares(\n        uint256 supply,\n        uint256 pool,\n        uint256 stake,\n        uint256 reducer,\n        uint256 minPrice\n    ) external view returns (uint256);\n\n    function getUnitPrice(\n        uint256 supply,\n        uint256 pool,\n        uint256 reducer,\n        uint256 minPrice\n    ) external view returns (uint256);\n}\n\ncontract LaunchPool is Initializable {\n    using SafeERC20 for IERC20;\n    // Address of the sponsor that controls launch pools and token shares\n    address private _sponsor;\n    // IPFS hash containing JSON informations about the project\n    string public metadata;\n    /*\n     * Address of the token that was previously deployed by sponsor\n     * _stakeMax must never surpass total token supply\n     */\n    address private _token;\n    // Price curve distribution contract address\n    address private _curve;\n    // Reducer used by curve dustribution\n    uint256 private _curveReducer;\n    // Reducer used by curve dustribution\n    uint256 private _curveMinPrice;\n    // Defines start timestamp for Pool opens\n    uint256 private _startTimestamp;\n    // Defines timestamp for Pool closes\n    uint256 private _endTimestamp;\n    // The total amount to be staked by investors\n    uint256 private _stakesMax;\n    // The minimum amount to be staken to approve launch pool\n    uint256 private _stakesMin;\n    // The total amount current staken at launch pool\n    uint256 private _stakesTotal;\n    // Prevent access elements bigger then stake size\n    uint256 private _stakesCount;\n    // The minimum amount for a unique stake\n    uint256 private _stakeAmountMin;\n    // The maximum amount a single stake could have\n    uint256 private _stakeClamp;\n    // 0 - Not Initialized - Not even set variables yet\n    // 1 - Initialized\n    //    Before Start Timestamp => Warm Up\n    //    After Start Timestamp => Staking/Unstaking\n    //    Before End Timestamp => Staking/Unstaking\n    //    After End Timestamp => Only Staking\n    // 2 - Paused - Staking stopped\n    // 3 - Calculating - Bonus calculation finished, start distribution\n    // 4 - Distributing - Finished distribution, start sponsor withdraw\n    // 5 - Finalized - Allow sponsor withdraw\n    // 6 - Aborted\n    enum Stages {\n        NotInitialized,\n        Initialized,\n        Paused,\n        Calculating,\n        Distributing,\n        Finalized,\n        Aborted\n    }\n    // Define current stage of launch pool\n    Stages public stage = Stages.NotInitialized;\n\n    // Token list to show on frontend\n    address[] private _tokenList;\n    mapping(address => bool) private _allowedTokens;\n    mapping(address => uint8) private _tokenDecimals;\n\n    struct TokenStake {\n        address investor;\n        address token;\n        uint256 amount;\n        // Result bonus calculated based on curve and reducer\n        uint256 shares;\n    }\n\n    // Stakes struct mapping\n    mapping(uint256 => TokenStake) private _stakes;\n    // Points to respective stake on _stakes\n    mapping(address => uint256[]) private _stakesByAccount;\n\n    // Storing calculation index and balance\n    uint256 private _stakesCalculated = 0;\n    uint256 private _stakesCalculatedBalance = 0;\n    // Storing token distribution index\n    uint256 private _stakesDistributed = 0;\n\n    // **** EVENTS ****\n\n    event Staked(\n        uint256 index,\n        address indexed investor,\n        address indexed token,\n        uint256 amount\n    );\n    event Unstaked(\n        uint256 index,\n        address indexed investor,\n        address indexed token,\n        uint256 amount\n    );\n    event Distributed(\n        uint256 index,\n        address indexed investor,\n        uint256 amount,\n        uint256 shares\n    );\n    event MetadataUpdated(string newHash);\n\n    // **** CONSTRUCTOR ****\n\n    function initialize(\n        address[] memory allowedTokens,\n        uint256[] memory uintArgs,\n        string memory _metadata,\n        address _owner,\n        address _sharesAddress,\n        address _curveAddress\n    ) public initializer {\n        // Allow at most 3 coins\n        require(\n            allowedTokens.length >= 1 && allowedTokens.length <= 3,\n            \"There must be at least 1 and at most 3 tokens\"\n        );\n        _stakesMin = uintArgs[0];\n        _stakesMax = uintArgs[1];\n        _startTimestamp = uintArgs[2];\n        _endTimestamp = uintArgs[3];\n        _curveReducer = uintArgs[4];\n        _stakeAmountMin = uintArgs[5];\n        _curveMinPrice = uintArgs[6];\n        _stakeClamp = uintArgs[7];\n        // Prevent stakes max never surpass Shares total supply\n        require(\n            IERC20(_sharesAddress).totalSupply() >=\n                InterfaceCurve(_curveAddress).getShares(\n                    _stakesMax,\n                    0,\n                    _stakesMax,\n                    _curveReducer,\n                    _curveMinPrice\n                ),\n            \"Shares token has not enough supply for staking distribution\"\n        );\n        // Store token allowance and treir decimals to easy normalize\n        for (uint256 i = 0; i < allowedTokens.length; i++) {\n            require(\n                ITokenDecimals(allowedTokens[i]).decimals() <= 18,\n                \"Token allowed has more than 18 decimals\"\n            );\n            _tokenDecimals[allowedTokens[i]] = ITokenDecimals(allowedTokens[i])\n                .decimals();\n            _allowedTokens[allowedTokens[i]] = true;\n            _tokenList.push(allowedTokens[i]);\n        }\n        _curve = _curveAddress;\n        _sponsor = _owner;\n        _token = _sharesAddress;\n        metadata = _metadata;\n        stage = Stages.Initialized;\n    }\n\n    // **** MODIFIERS ****\n\n    modifier isTokenAllowed(address _tokenAddr) {\n        require(_allowedTokens[_tokenAddr], \"Cannot deposit that token\");\n        _;\n    }\n\n    modifier isStaking() {\n        require(\n            block.timestamp > _startTimestamp,\n            \"Launch Pool has not started\"\n        );\n        require(stage == Stages.Initialized, \"Launch Pool is not staking\");\n        _;\n    }\n\n    modifier isPaused() {\n        require(stage == Stages.Paused, \"LaunchPool is not paused\");\n        _;\n    }\n\n    modifier isConcluded() {\n        require(\n            block.timestamp >= _endTimestamp,\n            \"LaunchPool end timestamp not reached\"\n        );\n        require(\n            _stakesTotal >= _stakesMin,\n            \"LaunchPool not reached minimum stake\"\n        );\n        _;\n    }\n\n    modifier isCalculating() {\n        require(\n            stage == Stages.Calculating,\n            \"Tokens are not yet ready to calculate\"\n        );\n        _;\n    }\n\n    modifier isDistributing() {\n        require(\n            stage == Stages.Distributing,\n            \"Tokens are not yet ready to distribute\"\n        );\n        _;\n    }\n\n    modifier isFinalized() {\n        require(stage == Stages.Finalized, \"Launch pool not finalized yet\");\n        _;\n    }\n\n    modifier hasStakeClamped(uint256 amount, address token) {\n        // The multiplications allow prevent that tokens with less than 18 decimals pass through\n        require(\n            amount * (10**(18 - _tokenDecimals[token])) <= _stakeClamp,\n            \"Stake maximum amount exceeded\"\n        );\n        _;\n    }\n\n    modifier hasMaxStakeReached(uint256 amount, address token) {\n        // The multiplications allow prevent that tokens with less than 18 decimals pass through\n        require(\n            _stakesTotal + amount * (10**(18 - _tokenDecimals[token])) <=\n                _stakesMax,\n            \"Maximum staked amount exceeded\"\n        );\n        _;\n    }\n\n    modifier onlySponsor() {\n        require(sponsor() == msg.sender, \"Sponsor: caller is not the sponsor\");\n        _;\n    }\n\n    // **** VIEWS ****\n\n    // Returns the sponsor address, owner of the contract\n    function sponsor() public view virtual returns (address) {\n        return _sponsor;\n    }\n\n    // Return the token list alllowed on launch pool\n    function tokenList() public view returns (address[] memory) {\n        return _tokenList;\n    }\n\n     // Return token shares address\n    function sharesAddress() public view returns (address) {\n        return _token;\n    }\n\n    /**\n     * @dev Returns detailed stakes from an investor.\n     * Stakes are returned as single dimension array.\n     * [0] Amount of token decimals for first investor stake\n     * [1] Stake amount of first stake\n     * and so on...\n     */\n    function stakesDetailedOf(address investor_)\n        public\n        view\n        returns (uint256[] memory)\n    {\n        uint256[] memory stakes =\n            new uint256[](_stakesByAccount[investor_].length * 2);\n        for (uint256 i = 0; i < _stakesByAccount[investor_].length; i++) {\n            stakes[i * 2] = _tokenDecimals[\n                _stakes[_stakesByAccount[investor_][i]].token\n            ];\n            stakes[i * 2 + 1] = _stakes[_stakesByAccount[investor_][i]].amount;\n        }\n        return stakes;\n    }\n\n    /**\n     * @dev Return global stake indexes for a specific investor.\n     */\n    function stakesOf(address investor_) public view returns (uint256[] memory) {\n        return _stakesByAccount[investor_];\n    }\n\n    function stakesList() public view returns (uint256[] memory) {\n        uint256[] memory stakes = new uint256[](_stakesCount);\n        for (uint256 i = 0; i < _stakesCount; i++) {\n            stakes[i] = _stakes[i].amount;\n        }\n        return stakes;\n    }\n\n    /**\n     * @dev Get Stake shares for interface calculation.\n     */\n    function getStakeShares(uint256 amount, uint256 balance)\n        public\n        view\n        returns (uint256)\n    {\n        return\n            InterfaceCurve(_curve).getShares(\n                _stakesMax,\n                balance,\n                amount,\n                _curveReducer,\n                _curveMinPrice\n            );\n    }\n\n    /**\n     * @dev Get general info about launch pool. Return Uint values\n     * 0 - Pool start timestamp\n     * 1 - Pool end timestamp\n     * 2 - Minimum stakes for pool approval\n     * 3 - Total stake allowed by launch pool\n     * 4 - Sum of all stakes\n     * 5 - Stakes Count\n     * 6 - Curve Reducer value\n     * 7 - Current stage of launch pool\n     * 8 - Minimum amount allowed to stake\n     * 9 - Minimum price paid for a share\n     * 10 - Maximum price that investors will pay for a share\n     */\n    function getGeneralInfos() public view returns (uint256[] memory values) {\n        values = new uint256[](11);\n        values[0] = _startTimestamp;\n        values[1] = _endTimestamp;\n        values[2] = _stakesMin;\n        values[3] = _stakesMax;\n        values[4] = _stakesTotal;\n        values[5] = _stakesCount;\n        values[6] = _curveReducer;\n        values[7] = uint256(stage);\n        values[8] = _stakeAmountMin;\n        values[9] = _curveMinPrice;\n        values[10] = _stakeClamp;\n        return values;\n    }\n\n    // **** INITIALIZED *****\n\n    /** @dev Update metadata informations for launch pool\n     **/\n    function updateMetadata(string memory _hash) external onlySponsor {\n        metadata = _hash;\n        emit MetadataUpdated(_hash);\n    }\n\n    // **** STAKING *****\n\n    /** @dev This allows investor to stake some ERC20 token. Make sure\n     * You `ERC20.approve` to this contract before you stake.\n     *\n     * Requirements:\n     *\n     * - `token` Address of token contract to be staked\n     * - `amount` The amount of tokens to stake\n     */\n    function stake(address token, uint256 amount)\n        external\n        isStaking\n        isTokenAllowed(token)\n        hasMaxStakeReached(amount, token)\n        hasStakeClamped(amount, token)\n    {\n        uint256 normalizedAmount = amount * (10**(18 - _tokenDecimals[token]));\n        require(\n            normalizedAmount >= _stakeAmountMin,\n            \"Stake below minimum amount\"\n        );\n        uint256 prevBalance = IERC20(token).balanceOf(address(this));\n        // If the transfer fails, we revert and don't record the amount.\n        IERC20(token).safeTransferFrom(msg.sender,address(this),amount);\n        uint256 resultAmount = IERC20(token).balanceOf(address(this))-prevBalance;\n        normalizedAmount = resultAmount * (10**(18 - _tokenDecimals[token]));\n        // Store stake id after insert it to the queue\n        TokenStake storage s = _stakes[_stakesCount];\n        s.investor = msg.sender;\n        s.token = token;\n        // Convert any token amount that has less than 18 decimals to 18\n        s.amount = normalizedAmount;\n\n        _stakesTotal += s.amount;\n        _stakesByAccount[msg.sender].push(_stakesCount);\n        emit Staked(_stakesCount, msg.sender, token, resultAmount);\n        _stakesCount += 1;\n    }\n\n    /** @dev This allows investor to unstake a previously stake. A investor stakeID\n     * must be passed as parameter. The investor stakes are created sequentially and could\n     * be listed using stakesOf().\n     *\n     * Requirements:\n     *\n     * - `stakeId` The index of stake from a sender investor. Initiating at 0.\n     */\n    function unstake(uint256 stakeId) external {\n        require(\n            stage == Stages.Initialized ||\n            stage == Stages.Aborted ||\n            stage == Stages.Paused,\n            \"No Staking/Paused/Aborted stage.\"\n        );\n        if (stage == Stages.Initialized) {\n            require(block.timestamp <= _endTimestamp, \"Launch Pool is closed\");\n        }\n        require(\n            _stakesByAccount[msg.sender].length > stakeId,\n            \"Stake index out of bounds\"\n        );\n\n        uint256 globalId = _stakesByAccount[msg.sender][stakeId];\n        TokenStake memory _stake = _stakes[globalId];\n        require(_stake.amount > 0, \"Stake already unstaked\");\n        // In case of 6 decimals (USDC, USDC, etc.) tokens need to be converted back.\n        IERC20(_stake.token).safeTransfer(\n            msg.sender,\n            _stake.amount / (10**(18 - _tokenDecimals[_stake.token]))\n        );\n\n        _stakesTotal -= _stake.amount;\n        _stakes[globalId].amount = 0;\n        emit Unstaked(globalId, msg.sender, _stake.token, _stake.amount);\n    }\n\n    /** @dev This allows sponsor pause staking preventing investor to stake.\n     * Only called by sponsor.\n     **/\n    function pause() external onlySponsor isStaking {\n        stage = Stages.Paused;\n    }\n\n    /** @dev Unpause launch pool returning back to staking/unstaking stage.\n     * Only called by sponsor.\n     **/\n    function unpause() external onlySponsor isPaused {\n        stage = Stages.Initialized;\n    }\n\n    /** @dev Extend staking period of the launch pool.\n     **/\n    function extendEndTimestamp(uint256 extension)\n        external\n        onlySponsor\n        isStaking\n    {\n        // Prevent extension to be bigger than 1 year, to not allow overflows\n        require(extension < 365 days, \"Extensions must be small than 1 year\");\n        _endTimestamp += extension;\n    }\n\n    /** @dev Lock stakes and proceed to Calculating phase of launch pool.\n     * Only called by sponsor.\n     **/\n    function lock() external onlySponsor isConcluded {\n        stage = Stages.Calculating;\n    }\n\n    // ***** CALCULATING ******\n\n    /** @dev Calculate how much shares each investor will receive accordingly to their stakes.\n     * Shares are calculated in order and skipped in case of has amount 0(unstaked).\n     * In case of low gas, the calculation stops at the current stake index.\n     * Only called by sponsor.\n     **/\n    function calculateSharesChunk() external onlySponsor isCalculating {\n        InterfaceCurve curve = InterfaceCurve(_curve);\n        while (_stakesCalculated < _stakesCount) {\n            // Break while loop in case of lack of gas\n            if (gasleft() < 100000) break;\n            // In case that stake has amount 0, it could be skipped\n            if (_stakes[_stakesCalculated].amount > 0) {\n                _stakes[_stakesCalculated].shares = curve.getShares(\n                    _stakesMax,\n                    _stakesCalculatedBalance,\n                    _stakes[_stakesCalculated].amount,\n                    _curveReducer,\n                    _curveMinPrice\n                );\n                _stakesCalculatedBalance += _stakes[_stakesCalculated].amount;\n            }\n            _stakesCalculated++;\n        }\n        if (_stakesCalculated >= _stakesCount) {\n            stage = Stages.Distributing;\n        }\n    }\n\n    // ***** DISTRIBUTING *****\n\n    /** @dev Distribute all shares calculated for each investor.\n     * Shares are distributed in order and skipped in case of has amount 0(unstaked).\n     * In case of low gas, the distribution stops at the current stake index.\n     * Only called by sponsor.\n     **/\n    function distributeSharesChunk() external onlySponsor isDistributing {\n        IERC20 token = IERC20(_token);\n        TokenStake memory _stake;\n        while (_stakesDistributed < _stakesCount) {\n            // Break while loop in case of lack of gas\n            if (gasleft() < 100000) break;\n            // In case that stake has amount 0, it could be skipped\n            _stake = _stakes[_stakesDistributed];\n            if (_stake.amount > 0) {\n                token.safeTransferFrom(_sponsor, _stake.investor, _stake.shares);\n                // Zero amount and shares to not be distribute again same stake\n                emit Distributed(\n                    _stakesDistributed,\n                    _stake.investor,\n                    _stake.amount,\n                    _stake.shares\n                );\n                //_stakes[_stakesDistributed].amount = 0;\n                _stakes[_stakesDistributed].shares = 0;\n            }\n            _stakesDistributed++;\n        }\n        if (_stakesDistributed >= _stakesCount) {\n            stage = Stages.Finalized;\n        }\n    }\n\n    // **** FINALIZED *****\n\n    /** @dev Sponsor withdraw stakes after finalized pool.\n     *  This could also be used to withdraw remain not used shared\n     **/\n    function withdrawStakes(address token) external onlySponsor isFinalized {\n        IERC20 instance = IERC20(token);\n        uint256 tokenBalance = instance.balanceOf(address(this));\n        instance.safeTransfer(msg.sender, tokenBalance);\n    }\n\n    // **** ABORTING ****\n\n    /** @dev Abort launch pool and allow all investors to unstake their tokens.\n     * Only called by sponsor.\n     **/\n    function abort() external onlySponsor {\n        // TODO Define rules to allow abort pool\n        stage = Stages.Aborted;\n    }\n}\n"
      },
      "/Users/filipemsoccol/Documents/doiim/otogo-smart-contracts/node_modules/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\n// solhint-disable-next-line compiler-version\npragma solidity ^0.8.0;\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n */\nabstract contract Initializable {\n\n    /**\n     * @dev Indicates that the contract has been initialized.\n     */\n    bool private _initialized;\n\n    /**\n     * @dev Indicates that the contract is in the process of being initialized.\n     */\n    bool private _initializing;\n\n    /**\n     * @dev Modifier to protect an initializer function from being invoked twice.\n     */\n    modifier initializer() {\n        require(_initializing || !_initialized, \"Initializable: contract is already initialized\");\n\n        bool isTopLevelCall = !_initializing;\n        if (isTopLevelCall) {\n            _initializing = true;\n            _initialized = true;\n        }\n\n        _;\n\n        if (isTopLevelCall) {\n            _initializing = false;\n        }\n    }\n}\n"
      },
      "/Users/filipemsoccol/Documents/doiim/otogo-smart-contracts/node_modules/@openzeppelin/contracts/token/ERC20/IERC20.sol": {
        "content": "// SPDX-License-Identifier: MIT\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 `recipient`.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transfer(address recipient, 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 `sender` to `recipient` 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(address sender, address recipient, uint256 amount) 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"
      },
      "/Users/filipemsoccol/Documents/doiim/otogo-smart-contracts/node_modules/@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol": {
        "content": "// SPDX-License-Identifier: MIT\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(IERC20 token, address to, uint256 value) internal {\n        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));\n    }\n\n    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) 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(IERC20 token, address spender, uint256 value) 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        // solhint-disable-next-line max-line-length\n        require((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(IERC20 token, address spender, uint256 value) 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(IERC20 token, address spender, uint256 value) 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) { // Return data is optional\n            // solhint-disable-next-line max-line-length\n            require(abi.decode(returndata, (bool)), \"SafeERC20: ERC20 operation did not succeed\");\n        }\n    }\n}\n"
      },
      "/Users/filipemsoccol/Documents/doiim/otogo-smart-contracts/node_modules/@openzeppelin/contracts/utils/Address.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\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    function isContract(address account) internal view returns (bool) {\n        // This method relies on extcodesize, which returns 0 for contracts in\n        // construction, since the code is only stored at the end of the\n        // constructor execution.\n\n        uint256 size;\n        // solhint-disable-next-line no-inline-assembly\n        assembly { size := extcodesize(account) }\n        return size > 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        // solhint-disable-next-line avoid-low-level-calls, avoid-call-value\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(address target, bytes memory data, string memory errorMessage) 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(address target, bytes memory data, uint256 value) 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(address target, bytes memory data, uint256 value, string memory errorMessage) 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        // solhint-disable-next-line avoid-low-level-calls\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(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {\n        require(isContract(target), \"Address: static call to non-contract\");\n\n        // solhint-disable-next-line avoid-low-level-calls\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(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {\n        require(isContract(target), \"Address: delegate call to non-contract\");\n\n        // solhint-disable-next-line avoid-low-level-calls\n        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return _verifyCallResult(success, returndata, errorMessage);\n    }\n\n    function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private 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                // solhint-disable-next-line no-inline-assembly\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": {
      "remappings": [],
      "optimizer": {
        "enabled": true,
        "runs": 200
      },
      "evmVersion": "istanbul",
      "libraries": {},
      "outputSelection": {
        "*": {
          "*": [
            "evm.bytecode",
            "evm.deployedBytecode",
            "abi"
          ]
        }
      }
    }
  }}