{
    "Function": "slitherConstructorConstantVariables",
    "File": "contracts/yieldspace/Strategy.sol",
    "Parent Contracts": [
        "contracts/utils/token/ERC20Rewards.sol",
        "contracts/utils/token/ERC20Permit.sol",
        "contracts/interfaces/external/IERC2612.sol",
        "contracts/utils/token/ERC20.sol",
        "contracts/interfaces/external/IERC20Metadata.sol",
        "contracts/interfaces/external/IERC20.sol",
        "contracts/utils/access/AccessControl.sol"
    ],
    "High-Level Calls": [],
    "Internal Calls": [],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "contract Strategy is AccessControl, ERC20Rewards {\n    using TransferHelper for IERC20;\n    using CastU256U128 for uint256; // Inherited from ERC20Rewards\n    using CastU128I128 for uint128;\n\n    event YieldSet(ILadle ladle, ICauldron cauldron);\n    event TokenJoinReset(address join);\n    event TokenIdSet(bytes6 id);\n    event NextPoolSet(IPool indexed pool, bytes6 indexed seriesId);\n    event PoolEnded(address pool);\n    event PoolStarted(address pool);\n    event Invest(uint256 minted);\n    event Divest(uint256 burnt);\n\n    IERC20 public immutable base;                // Base token for this strategy\n    bytes6 public baseId;                        // Identifier for the base token in Yieldv2\n    address public baseJoin;                     // Yield v2 Join to deposit token when borrowing\n    ILadle public ladle;                         // Gateway to the Yield v2 Collateralized Debt Engine\n    ICauldron public cauldron;                   // Accounts in the Yield v2 Collateralized Debt Engine\n    bytes12 public vaultId;                      // Vault used to borrow fyToken\n\n    IPool public pool;                           // Current pool that this strategy invests in\n    bytes6 public seriesId;                      // SeriesId for the current pool in Yield v2\n    IFYToken public fyToken;                     // Current fyToken for this strategy\n\n    IPool public nextPool;                       // Next pool that this strategy will invest in\n    bytes6 public nextSeriesId;                  // SeriesId for the next pool in Yield v2\n\n    uint256 public cached;                       // LP tokens owned by the strategy after the last operation\n\n    constructor(string memory name, string memory symbol, uint8 decimals, ILadle ladle_, IERC20 base_, bytes6 baseId_)\n        ERC20Rewards(name, symbol, decimals)\n    { \n        require(\n            ladle_.cauldron().assets(baseId_) == address(base_),\n            \"Mismatched baseId\"\n        );\n        base = base_;\n        baseId = baseId_;\n        baseJoin = ladle_.joins(baseId_);\n\n        ladle = ladle_;\n        cauldron = ladle_.cauldron();\n    }\n\n    modifier beforeMaturity() {\n        require (\n            fyToken.maturity() >= uint32(block.timestamp),\n            \"Only before maturity\"\n        );\n        _;\n    }\n\n    modifier afterMaturity() {\n        require (\n            fyToken == IFYToken(address(0)) || fyToken.maturity() < uint32(block.timestamp),\n            \"Only after maturity\"\n        );\n        _;\n    }\n\n    /// @dev Set a new Ladle and Cauldron\n    /// @notice Use with extreme caution, only for Ladle replacements\n    function setYield(ILadle ladle_, ICauldron cauldron_)\n        public\n        afterMaturity\n        auth\n    {\n        ladle = ladle_;\n        cauldron = ladle_.cauldron();\n        emit YieldSet(ladle_, cauldron_);\n    }\n\n    /// @dev Set a new base token id\n    /// @notice Use with extreme caution, only for token reconfigurations in Cauldron\n    function setTokenId(bytes6 baseId_)\n        public\n        afterMaturity\n        auth\n    {\n        require(\n            ladle.cauldron().assets(baseId_) == address(base),\n            \"Mismatched baseId\"\n        );\n        baseId = baseId_;\n        emit TokenIdSet(baseId_);\n    }\n\n    /// @dev Reset the base token join\n    /// @notice Use with extreme caution, only for Join replacements\n    function resetTokenJoin()\n        public\n        afterMaturity\n        auth\n    {\n        baseJoin = ladle.joins(baseId);\n        emit TokenJoinReset(baseJoin);\n    }\n\n    /// @dev Set the next pool to invest in\n    function setNextPool(IPool pool_, bytes6 seriesId_) \n        public\n        auth\n    {\n        require(\n            base == pool_.base(),\n            \"Mismatched base\"\n        );\n        DataTypes.Series memory series = cauldron.series(seriesId_);\n        require(\n            series.fyToken == pool_.fyToken(),\n            \"Mismatched seriesId\"\n        );\n\n        nextPool = pool_;\n        nextSeriesId = seriesId_;\n\n        emit NextPoolSet(pool_, seriesId_);\n    }\n\n    /// @dev Start the strategy investments in the next pool\n    /// @notice When calling this function for the first pool, some underlying needs to be transferred to the strategy first, using a batchable router.\n    function startPool()\n        public\n    {\n        require(pool == IPool(address(0)), \"Current pool exists\");\n        require(nextPool != IPool(address(0)), \"Next pool not set\");\n\n        pool = nextPool;\n        fyToken = pool.fyToken();\n        seriesId = nextSeriesId;\n\n        delete nextPool;\n        delete nextSeriesId;\n\n        (vaultId, ) = ladle.build(seriesId, baseId, 0);\n\n        // Find pool proportion p = tokenReserves/(tokenReserves + fyTokenReserves)\n        // Deposit (investment * p) base to borrow (investment * p) fyToken\n        //   (investment * p) fyToken + (investment * (1 - p)) base = investment\n        //   (investment * p) / ((investment * p) + (investment * (1 - p))) = p\n        //   (investment * (1 - p)) / ((investment * p) + (investment * (1 - p))) = 1 - p\n\n        uint256 baseBalance = base.balanceOf(address(this));\n        require(baseBalance > 0, \"No funds to start with\");\n\n        uint256 baseInPool = base.balanceOf(address(pool));\n        uint256 fyTokenInPool = fyToken.balanceOf(address(pool));\n        \n        uint256 baseToPool = (baseBalance * baseInPool) / (baseInPool + fyTokenInPool);  // Rounds down\n        uint256 fyTokenToPool = baseBalance - baseToPool;        // fyTokenToPool is rounded up\n\n        // Borrow fyToken with base as collateral\n        base.safeTransfer(baseJoin, fyTokenToPool);\n        int128 fyTokenToPool_ = fyTokenToPool.u128().i128();\n        ladle.pour(vaultId, address(pool), fyTokenToPool_, fyTokenToPool_);\n\n        // Mint LP tokens with (investment * p) fyToken and (investment * (1 - p)) base\n        base.safeTransfer(address(pool), baseToPool);\n        (,, cached) = pool.mint(address(this), true, 0); // We don't care about slippage\n\n        if (_totalSupply == 0) _mint(msg.sender, cached); // Initialize the strategy if needed\n\n        emit PoolStarted(address(pool));\n    }\n\n    /// @dev Divest out of a pool once it has matured\n    function endPool()\n        public\n        afterMaturity\n    {\n        uint256 toDivest = pool.balanceOf(address(this));\n        \n        // Burn lpTokens\n        IERC20(address(pool)).safeTransfer(address(pool), toDivest);\n        (,, uint256 fyTokenDivested) = pool.burn(address(this), 0, 0); // We don't care about slippage\n        \n        // Repay with fyToken as much as possible\n        DataTypes.Balances memory balances_ = cauldron.balances(vaultId);\n        uint256 debt = balances_.art;\n        uint256 toRepay = (debt >= fyTokenDivested) ? fyTokenDivested : debt;\n        if (toRepay > 0) {\n            IERC20(address(fyToken)).safeTransfer(address(fyToken), toRepay);\n            int128 toRepay_ = toRepay.u128().i128();\n            ladle.pour(vaultId, address(this), 0, -toRepay_);\n            debt -= toRepay;\n        }\n\n        // Redeem any fyToken surplus\n        uint256 toRedeem = fyTokenDivested - toRepay;\n        if (toRedeem > 0) {\n            IERC20(address(fyToken)).safeTransfer(address(fyToken), toRedeem);\n            fyToken.redeem(address(this), toRedeem);\n        }\n\n        // Repay with underlying if there is still any debt\n        if (debt > 0) {\n            base.safeTransfer(address(baseJoin), cauldron.debtToBase(seriesId, debt.u128())); // The strategy can't lose money due to the pool invariant, there will always be enough if we get here.\n            int128 debt_ = debt.u128().i128();\n            ladle.close(vaultId, address(this), 0, -debt_);   // Takes a fyToken amount as art parameter\n        }\n\n        // Withdraw all collateral\n        ladle.pour(vaultId, address(this), -(balances_.ink.i128()), 0);\n\n        emit PoolEnded(address(pool));\n\n        // Clear up\n        delete pool;\n        delete fyToken;\n        delete seriesId;\n        delete cached;\n        \n        ladle.destroy(vaultId);\n        delete vaultId;\n    }\n\n    /// @dev Mint strategy tokens.\n    /// @notice The lp tokens that the user contributes need to have been transferred previously, using a batchable router.\n    function mint(address to)\n        public\n        beforeMaturity\n        returns (uint256 minted)\n    {\n        // minted = supply * value(deposit) / value(strategy)\n        uint256 deposit = pool.balanceOf(address(this)) - cached;\n        minted = _totalSupply * deposit / cached;\n        cached += deposit;\n\n        _mint(to, minted);\n    }\n\n    /// @dev Burn strategy tokens to withdraw lp tokens. The lp tokens obtained won't be of the same pool that the investor deposited,\n    /// if the strategy has swapped to another pool.\n    /// @notice The strategy tokens that the user burns need to have been transferred previously, using a batchable router.\n    function burn(address to)\n        public\n        returns (uint256 withdrawal)\n    {\n        // strategy * burnt/supply = withdrawal\n        uint256 burnt = _balanceOf[address(this)];\n        withdrawal = cached * burnt / _totalSupply;\n        cached -= withdrawal;\n\n        _burn(address(this), burnt);\n        IERC20(address(pool)).safeTransfer(to, withdrawal);\n    }\n}"
}