{
    "Function": "slitherConstructorConstantVariables",
    "File": "contracts/UpsideProtocol.sol",
    "Parent Contracts": [
        "node_modules/@openzeppelin/contracts/access/Ownable.sol",
        "node_modules/@openzeppelin/contracts/utils/Context.sol"
    ],
    "High-Level Calls": [],
    "Internal Calls": [],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "contract UpsideProtocol is Ownable {\n    using SafeERC20 for IERC20Metadata;\n\n    struct MetaCoinInfo {\n        address deployer;\n        bool isFreelyTransferable;\n        uint256 liquidityTokenReserves;\n        uint256 metaCoinReserves;\n        uint256 createdAtUnix;\n    }\n\n    struct FeeInfo {\n        address tokenizeFeeDestinationAddress;\n        uint32 swapFeeDecayInterval;\n        bool tokenizeFeeEnabled;\n        uint16 swapFeeStartingBp;\n        uint16 swapFeeDecayBp;\n        uint16 swapFeeFinalBp;\n        uint16 swapFeeSellBp;\n        uint16 swapFeeDeployerBp;\n    }\n\n    // @dev Constants\n    string private constant META_COIN_DEFAULT_NAME = \"UPSIDE\";\n    string private constant META_COIN_DEFAULT_SYMBOL = \"UPSIDE\";\n    uint256 private constant META_COIN_DEFAULT_TOTAL_SUPPLY = 1_000_000 * (10 ** 18);\n    uint256 public constant INITIAL_LIQUIDITY_RESERVES = 10_000 * (10 ** 6);\n    uint256 public constant WITHDRAW_LIQUIDITY_COOLDOWN = 14 days;\n\n    address public liquidityTokenAddress;\n    address public stakingContractAddress;\n    uint256 public withdrawLiquidityTimerStartTime;\n    uint256 public claimableProtocolFees; // @dev This is always in liquidity tokens\n    FeeInfo public feeInfo;\n\n    // @dev stores data on which addresses are whitelisted to transfer MetaCoins (per meta coin)\n    mapping(address metaCoinAddress => mapping(address walletAddress => bool isWhitelisted))\n        private metaCoinWhitelistMap;\n    mapping(address metaCoinAddress => MetaCoinInfo) public metaCoinInfoMap;\n    mapping(string url => address metaCoinAddress) public urlToMetaCoinMap;\n    // @dev This is always in MetaCoins (not liquidity tokens)\n    mapping(address metaCoinAddress => mapping(address walletAddress => uint256 deployerFeeClaimable))\n        public claimableDeployerFees;\n    mapping(address tokenizeFeeAddress => uint256 tokenizeFeeAmount) public tokenizeFeeMap;\n\n    event UrlTokenized(address metaCoinAddress, string url);\n    event FeeInfoSet(FeeInfo feeInfo);\n    event Trade(\n        address metaCoinAddress,\n        bool isBuy,\n        address sender,\n        uint256 tokenAmount,\n        uint256 tokenAmountAfterFee,\n        uint256 amountOut,\n        address recipient\n    );\n    event MetaCoinWhitelistSet(address metaCoinAddress, address walletAddress, bool isWhitelisted);\n    event SwapFeeProcessed(\n        address metaCoinAddress,\n        bool isBuy,\n        uint256 secondsPassed,\n        uint256 swapFeeBp,\n        uint256 totalFee, // Total fee for the swap\n        uint256 feeToProtocol, // Only used for buy swaps\n        uint256 feeToDeployer, // Only used for sell swaps\n        uint256 feeToStakers // Only used for sell swaps\n    );\n    event MetaCoinTransferabilitySet(address metaCoinAddress, bool whitelistDisabled);\n    event LiquidityWithdrawn(address metaCoinAddress, uint256 liquidityTokenReserves, uint256 metaCoinReserves);\n    event ProtocolFeeClaimed(uint256 totalFeeClaimed, address recipient);\n    event DeployerFeeClaimed(address metaCoinAddress, uint256 tokenAmount, address recipient);\n    event WithdrawLiquidityTimerStarted(uint256 functionEnabledFromTs);\n    event StakingContractAddressSet(address stakingContractAddress);\n    event TokenizeFeeSet(address tokenizeFeeAddress, uint256 tokenizeFeeAmount);\n    event MetaCoinNameSymbolSet(address metaCoinAddress, string name, string symbol);\n\n    error MetaCoinExists();\n    error MetaCoinNonExistent();\n    error InsufficientOutput();\n    error InsufficientLiquidity();\n    error InvalidSetting();\n    error AlreadyTransferable();\n    error CooldownTimerNotEnded();\n    error TokenizeFeeInvalid();\n\n    constructor(address _owner) Ownable(_owner) {}\n\n    /// @notice Returns true/false based on whether token transfer should be allowed\n    /// @param _metaCoinAddress Address of the MetaCoin\n    /// @param _walletAddress The wallet address to check on the whitelist\n    /// @return True or false\n    function metaCoinWhitelist(address _metaCoinAddress, address _walletAddress) external view returns (bool) {\n        if (_walletAddress == address(this) || _walletAddress == stakingContractAddress) {\n            return true;\n        }\n        return metaCoinWhitelistMap[_metaCoinAddress][_walletAddress];\n    }\n\n    /// @notice Allows anyone to tokenize any url\n    /// @param _url The url to tokenize\n    /// @return metaCoinAddress The address of the newly deployed MetaCoin\n    /// @dev This function may require a fee to be paid in \"tokenizeFeeToken\"\n    function tokenize(string calldata _url, address _tokenizeFeeAddress) external returns (address metaCoinAddress) {\n        if (urlToMetaCoinMap[_url] != address(0)) {\n            revert MetaCoinExists();\n        }\n\n        FeeInfo storage fee = feeInfo;\n\n        // Handle tokenize fee\n        // @dev We want to be able to accept many different ERC20 tokens as opposed to just one\n        if (fee.tokenizeFeeEnabled) {\n            if (tokenizeFeeMap[_tokenizeFeeAddress] == 0) {\n                revert TokenizeFeeInvalid();\n            }\n            IERC20Metadata(_tokenizeFeeAddress).safeTransferFrom(\n                msg.sender,\n                fee.tokenizeFeeDestinationAddress,\n                tokenizeFeeMap[_tokenizeFeeAddress]\n            );\n        }\n\n        metaCoinAddress = address(\n            new UpsideMetaCoin(\n                META_COIN_DEFAULT_NAME,\n                META_COIN_DEFAULT_SYMBOL,\n                META_COIN_DEFAULT_TOTAL_SUPPLY,\n                address(this)\n            )\n        );\n        urlToMetaCoinMap[_url] = metaCoinAddress;\n\n        metaCoinInfoMap[metaCoinAddress] = MetaCoinInfo(\n            msg.sender,\n            false,\n            INITIAL_LIQUIDITY_RESERVES,\n            META_COIN_DEFAULT_TOTAL_SUPPLY,\n            block.timestamp\n        );\n\n        IUpsideStaking(stakingContractAddress).whitelistStakingToken(metaCoinAddress);\n\n        emit UrlTokenized(metaCoinAddress, _url);\n        return metaCoinAddress;\n    }\n\n    /// @notice Computes the Time Fee (swap fee) for any given valid MetaCoin address\n    /// @param _metaCoinAddress The address of the MetaCoin to compute for\n    /// @return secondsPassed The number of seconds passed since deployment\n    /// @return swapFeeBp The swap percentage fee in basis-points (bp)\n    /// @return deployerFeeBp The deployer percentage fee in basis-points (bp)\n    /// @dev Swap fee is what's taken from the user. Deployer fee is a percentage of the swap fee.\n    /// @dev EG: Input is 100, swap fee is 10% = 10. Deployer fee is 10% = 1\n    /// @dev Expectation is there will always be a fee >0\n    function computeTimeFee(\n        address _metaCoinAddress\n    ) public view returns (uint256 secondsPassed, uint256 swapFeeBp, uint256 deployerFeeBp) {\n        MetaCoinInfo storage metaCoinInfo = metaCoinInfoMap[_metaCoinAddress];\n        FeeInfo storage fee = feeInfo;\n\n        if (metaCoinInfo.deployer == address(0)) {\n            revert MetaCoinNonExistent();\n        }\n\n        secondsPassed = block.timestamp - metaCoinInfo.createdAtUnix;\n        uint256 intervalsElapsed = secondsPassed / fee.swapFeeDecayInterval;\n        uint256 feeReduction = intervalsElapsed * fee.swapFeeDecayBp;\n\n        if (feeReduction >= (fee.swapFeeStartingBp - fee.swapFeeFinalBp)) {\n            swapFeeBp = fee.swapFeeFinalBp;\n        } else {\n            swapFeeBp = fee.swapFeeStartingBp - feeReduction;\n        }\n        deployerFeeBp = fee.swapFeeDeployerBp;\n    }\n\n    /// @notice Used internally to handle swap fees\n    /// @param _metaCoinAddress The MetaCoin address to process swap fees for\n    /// @param _isBuy Flag to define if this is a BUY or SELL. BUY = true\n    /// @param _tokenAmount The number of tokens the user is providing to swap\n    /// @param _deployer The address of the MetaCoin deployer\n    /// @return tokenAmountAfterFee The token amount used within the bonding curve after fees are deducted\n    /// @dev Expectation is there will always be a fee >0\n    function processSwapFee(\n        address _metaCoinAddress,\n        bool _isBuy,\n        uint256 _tokenAmount,\n        address _deployer\n    ) internal returns (uint256 tokenAmountAfterFee) {\n        (uint256 secondsPassed, uint256 swapFeeBp, uint256 swapDeployerFeeBp) = computeTimeFee(_metaCoinAddress);\n\n        uint256 fee;\n        uint256 feeToProtocol;\n        uint256 feeToDeployer;\n        uint256 feeToStakers;\n\n        if (_isBuy) {\n            // @dev On buy, the dynamic time fee is used\n            fee = (_tokenAmount * swapFeeBp) / 10000;\n            tokenAmountAfterFee = _tokenAmount - fee;\n\n            claimableProtocolFees += fee;\n            feeToProtocol = fee;\n        } else {\n            // @dev On sell, a static percentage bp is used (impl could be significantly improved to save gas)\n            fee = (_tokenAmount * feeInfo.swapFeeSellBp) / 10000;\n            tokenAmountAfterFee = _tokenAmount - fee;\n\n            feeToDeployer = (fee * swapDeployerFeeBp) / 10000;\n            claimableDeployerFees[_metaCoinAddress][_deployer] += feeToDeployer;\n            feeToStakers = fee - feeToDeployer;\n\n            IERC20Metadata(_metaCoinAddress).approve(stakingContractAddress, feeToStakers);\n            IUpsideStaking(stakingContractAddress).distributeRewards(_metaCoinAddress, feeToStakers);\n        }\n\n        emit SwapFeeProcessed(\n            _metaCoinAddress,\n            _isBuy,\n            secondsPassed,\n            _isBuy ? swapFeeBp : feeInfo.swapFeeSellBp,\n            fee,\n            feeToProtocol,\n            feeToDeployer,\n            feeToStakers\n        );\n    }\n\n    /// @notice Allows users to swap tokens in both directions\n    /// @param _metaCoinAddress The MetaCoin address to swap\n    /// @param _isBuy Flag to define if this is a BUY or SELL. BUY = true\n    /// @param _tokenAmount The number of tokens to swap\n    /// @param _minimumOut The minimum number of tokens to get back\n    /// @param _recipient The address to send the output tokens to\n    /// @return amountOut The number of tokens resulting from the swap\n    function swap(\n        address _metaCoinAddress,\n        bool _isBuy,\n        uint256 _tokenAmount,\n        uint256 _minimumOut,\n        address _recipient\n    ) external returns (uint256 amountOut) {\n        MetaCoinInfo storage metaCoinInfo = metaCoinInfoMap[_metaCoinAddress];\n\n        if (metaCoinInfo.deployer == address(0)) {\n            revert MetaCoinNonExistent();\n        }\n\n        if (_isBuy) {\n            IERC20Metadata(liquidityTokenAddress).safeTransferFrom(msg.sender, address(this), _tokenAmount);\n        } else {\n            IERC20Metadata(_metaCoinAddress).safeTransferFrom(msg.sender, address(this), _tokenAmount);\n        }\n\n        uint256 amountInAfterFee = processSwapFee(_metaCoinAddress, _isBuy, _tokenAmount, metaCoinInfo.deployer);\n\n        uint256 newLiquidityTokenReserves;\n        uint256 newMetaCoinReserves;\n        if (_isBuy) {\n            newLiquidityTokenReserves = metaCoinInfo.liquidityTokenReserves + amountInAfterFee;\n            amountOut = (metaCoinInfo.metaCoinReserves * amountInAfterFee) / newLiquidityTokenReserves;\n            newMetaCoinReserves = metaCoinInfo.metaCoinReserves - amountOut;\n        } else {\n            newMetaCoinReserves = metaCoinInfo.metaCoinReserves + amountInAfterFee;\n            amountOut = (metaCoinInfo.liquidityTokenReserves * amountInAfterFee) / newMetaCoinReserves;\n            newLiquidityTokenReserves = metaCoinInfo.liquidityTokenReserves - amountOut;\n\n            if (newLiquidityTokenReserves < INITIAL_LIQUIDITY_RESERVES) revert InsufficientLiquidity();\n        }\n        if (_minimumOut > amountOut) revert InsufficientOutput();\n\n        metaCoinInfo.liquidityTokenReserves = newLiquidityTokenReserves;\n        metaCoinInfo.metaCoinReserves = newMetaCoinReserves;\n\n        emit Trade(_metaCoinAddress, _isBuy, msg.sender, _tokenAmount, amountInAfterFee, amountOut, _recipient);\n\n        if (_isBuy) {\n            IERC20Metadata(_metaCoinAddress).safeTransfer(_recipient, amountOut);\n        } else {\n            IERC20Metadata(liquidityTokenAddress).safeTransfer(_recipient, amountOut);\n        }\n    }\n\n    /// @notice Allows deployers of MetaCoin's to claim their generated fees\n    /// @param _metaCoinAddress Address of the MetaCoin to claim fees from\n    /// @param _recipient Address where claimed deployer fees should be sent to\n    function claimDeployerFees(address _metaCoinAddress, address _recipient) external {\n        uint256 fees = claimableDeployerFees[_metaCoinAddress][msg.sender];\n        claimableDeployerFees[_metaCoinAddress][msg.sender] = 0;\n        emit DeployerFeeClaimed(_metaCoinAddress, fees, _recipient);\n\n        IERC20Metadata(_metaCoinAddress).safeTransfer(_recipient, fees);\n    }\n\n    /// @notice Allows the owner of the contract to initialize the contract\n    /// @param _liquidityTokenAddress The liquidity token address that should be used moving forward\n    /// @dev This function can only be called once.\n    function init(address _liquidityTokenAddress) external onlyOwner {\n        require(liquidityTokenAddress == address(0), \"ALREADY INITIALISED\");\n        liquidityTokenAddress = _liquidityTokenAddress;\n    }\n\n    /// @notice Allows Owner to set whitelisted addresses which controls who can transfer MetaCoin per MetaCoin\n    /// @param _metaCoinAddresses Array of MetaCoin addresses to update\n    /// @param _walletAddresses Array of wallet addresses to set whitelist flag for\n    /// @param _isWhitelisted Array of boolean's setting whitelist flag. True = whitelisted\n    function setMetaCoinWhitelist(\n        address[] calldata _metaCoinAddresses,\n        address[] calldata _walletAddresses,\n        bool[] calldata _isWhitelisted\n    ) external onlyOwner {\n        for (uint256 i; i < _metaCoinAddresses.length; ) {\n            metaCoinWhitelistMap[_metaCoinAddresses[i]][_walletAddresses[i]] = _isWhitelisted[i];\n            emit MetaCoinWhitelistSet(_metaCoinAddresses[i], _walletAddresses[i], _isWhitelisted[i]);\n            unchecked {\n                ++i;\n            }\n        }\n    }\n\n    /// @notice Allows Owner to set Swap Fee and Tokenize Fee settings\n    /// @param _newFeeInfo Struct with Swap Fee and Tokenize Fee settings\n    function setFeeInfo(FeeInfo calldata _newFeeInfo) external onlyOwner {\n        if (\n            _newFeeInfo.swapFeeDeployerBp > 10000 ||\n            _newFeeInfo.swapFeeDecayBp > 10000 ||\n            _newFeeInfo.swapFeeFinalBp > 10000 ||\n            _newFeeInfo.swapFeeStartingBp > 10000 ||\n            _newFeeInfo.swapFeeSellBp > 10000 ||\n            _newFeeInfo.tokenizeFeeDestinationAddress == address(0) ||\n            _newFeeInfo.swapFeeStartingBp < _newFeeInfo.swapFeeFinalBp ||\n            _newFeeInfo.swapFeeDecayInterval == 0\n        ) {\n            revert InvalidSetting();\n        }\n\n        feeInfo = _newFeeInfo;\n        emit FeeInfoSet(_newFeeInfo);\n    }\n\n    /// @notice Allows Owner to withdraw liquidity from bonding curves\n    /// @param _metaCoinAddresses An array of MetaCoin addresses to withdraw liquidity from\n    function withdrawLiquidity(address[] calldata _metaCoinAddresses) external onlyOwner {\n        /// @dev A GLOBAL timer is used - this impacts ALL MetaCoin's past and future\n        // If the timer was not started, start it\n        if (withdrawLiquidityTimerStartTime == 0) {\n            withdrawLiquidityTimerStartTime = block.timestamp;\n\n            // Emit event so it can be tracked\n            emit WithdrawLiquidityTimerStarted(block.timestamp + WITHDRAW_LIQUIDITY_COOLDOWN);\n            return;\n        }\n\n        // Ensure if the countdown was started, the entire cooldown period has passed\n        uint256 withdrawalAllowedBlockTimestamp = withdrawLiquidityTimerStartTime + WITHDRAW_LIQUIDITY_COOLDOWN;\n        if (withdrawalAllowedBlockTimestamp > block.timestamp) revert CooldownTimerNotEnded();\n\n        // Withdrawal logic\n        uint256 tokensToWithdraw;\n\n        for (uint256 i; i < _metaCoinAddresses.length; ) {\n            MetaCoinInfo storage metaCoinInfo = metaCoinInfoMap[_metaCoinAddresses[i]];\n            uint256 liquidityTokensInCurve = metaCoinInfo.liquidityTokenReserves - INITIAL_LIQUIDITY_RESERVES;\n            uint256 metaTokensInCurve = metaCoinInfo.metaCoinReserves;\n\n            // Update the reserve\n            metaCoinInfo.liquidityTokenReserves = INITIAL_LIQUIDITY_RESERVES;\n            metaCoinInfo.metaCoinReserves = 0;\n\n            // Add withdrawal of liquidity tokens to running sum (for transfer later in one go)\n            tokensToWithdraw += liquidityTokensInCurve;\n\n            // Transfer MetaCoin\n            IERC20Metadata(_metaCoinAddresses[i]).safeTransfer(msg.sender, metaTokensInCurve);\n\n            emit LiquidityWithdrawn(_metaCoinAddresses[i], liquidityTokensInCurve, metaTokensInCurve);\n            unchecked {\n                ++i;\n            }\n        }\n\n        // Transfer the total number of liquidity tokens\n        IERC20Metadata(liquidityTokenAddress).safeTransfer(msg.sender, tokensToWithdraw);\n    }\n\n    /// @notice Allows Owner to disable whitelist for specific MetaCoins\n    /// @dev This can only be called once and is permanent for that MetaCoin\n    function disableWhitelist(address _metaCoinAddress) external onlyOwner {\n        MetaCoinInfo storage metaCoinInfo = metaCoinInfoMap[_metaCoinAddress];\n\n        if (metaCoinInfo.deployer == address(0)) {\n            revert MetaCoinNonExistent();\n        }\n\n        if (metaCoinInfo.isFreelyTransferable) revert AlreadyTransferable();\n\n        metaCoinInfo.isFreelyTransferable = true;\n        emit MetaCoinTransferabilitySet(_metaCoinAddress, true);\n    }\n\n    /// @notice Allows Owner to claim protocol fees\n    /// @param _recipient The address where the claimed protocol fees should be sent to\n    function claimProtocolFees(address _recipient) external onlyOwner {\n        uint256 fees = claimableProtocolFees;\n        claimableProtocolFees = 0;\n        emit ProtocolFeeClaimed(fees, _recipient);\n\n        IERC20Metadata(liquidityTokenAddress).safeTransfer(_recipient, fees);\n    }\n\n    /// @notice Allows Owner to update staking contract address\n    /// @param _newStakingContractAddress Address of the new staking contract address\n    function setStakingContractAddress(address _newStakingContractAddress) external onlyOwner {\n        stakingContractAddress = _newStakingContractAddress;\n        emit StakingContractAddressSet(_newStakingContractAddress);\n    }\n\n    /// @notice Allows Owner to set tokenize fee per token address\n    /// @param _tokenizeFeeAddress Token address to set\n    /// @param _tokenizeFeeAmount Tokenize fee amount for this tokenize fee address\n    function setTokenizeFee(address _tokenizeFeeAddress, uint256 _tokenizeFeeAmount) external onlyOwner {\n        tokenizeFeeMap[_tokenizeFeeAddress] = _tokenizeFeeAmount;\n        emit TokenizeFeeSet(_tokenizeFeeAddress, _tokenizeFeeAmount);\n    }\n\n    /// @notice Allows Owner to set new ERC20 name and symbol for specific MetaCoin\n    /// @param _metaCoinAddress The MetaCoin address to update\n    /// @param _name The new ERC20 name\n    /// @param _symbol The new ERC20 symbol\n    function setMetaCoinNameSymbol(\n        address _metaCoinAddress,\n        string memory _name,\n        string memory _symbol\n    ) external onlyOwner {\n        MetaCoinInfo storage metaCoinInfo = metaCoinInfoMap[_metaCoinAddress];\n\n        if (metaCoinInfo.deployer == address(0)) {\n            revert MetaCoinNonExistent();\n        }\n\n        UpsideMetaCoin(_metaCoinAddress).setNameAndSymbol(_name, _symbol);\n\n        emit MetaCoinNameSymbolSet(_metaCoinAddress, _name, _symbol);\n    }\n}"
}