creation_sourcecode: {{
    "language": "Solidity",
    "sources": {
      "/var/www/html/boltfork/posley/AirPuff/contracts/AirPuffHandlerM.sol": {
        "content": "// SPDX-License-Identifier: UNLICENSED\r\npragma solidity 0.8.21;\r\n\r\nimport \"@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol\";\r\nimport \"@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol\";\r\nimport \"@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol\";\r\nimport \"@openzeppelin/contracts-upgradeable/utils/math/MathUpgradeable.sol\";\r\nimport \"@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol\";\r\nimport \"./interfaces/ILending.sol\";\r\nimport \"./interfaces/IAirPuffVaultM.sol\";\r\nimport \"./interfaces/AggregatorV3Interface.sol\";\r\nimport \"./interfaces/IAPI3Oracle.sol\";\r\n\r\ninterface IVectorOracle {\r\n        function consultvETHPrice()\r\n        external\r\n        view\r\n        returns (uint256);\r\n}\r\n\r\ninterface IWETH {\r\n    function deposit() external payable;\r\n    function withdraw(uint256) external;\r\n    function decimals() external view returns (uint8);\r\n}\r\n\r\ninterface IAsset {\r\n    // The IAsset interface might not explicitly define methods\r\n    // since it's used as a type marker in Balancer's system.\r\n    // Actual interactions with assets (tokens) would use the standard ERC20 methods or equivalent.\r\n}\r\n\r\ninterface ISwapRouter {\r\n    struct ExactInputSingleParams {\r\n        address tokenIn;\r\n        address tokenOut;\r\n        uint24 fee;\r\n        address recipient;\r\n        uint deadline;\r\n        uint amountIn;\r\n        uint amountOutMinimum;\r\n        uint160 sqrtPriceLimitX96;\r\n    }\r\n\r\n    /// @notice Swaps amountIn of one token for as much as possible of another token\r\n    /// @param params The parameters necessary for the swap, encoded as ExactInputSingleParams in calldata\r\n    /// @return amountOut The amount of the received token\r\n    function exactInputSingle(\r\n        ExactInputSingleParams calldata params\r\n    ) external payable returns (uint amountOut);\r\n\r\n    struct ExactInputParams {\r\n        bytes path;\r\n        address recipient;\r\n        uint deadline;\r\n        uint amountIn;\r\n        uint amountOutMinimum;\r\n    }\r\n\r\n    /// @notice Swaps amountIn of one token for as much as possible of another along the specified path\r\n    /// @param params The parameters necessary for the multi-hop swap, encoded as ExactInputParams in calldata\r\n    /// @return amountOut The amount of the received token\r\n    function exactInput(\r\n        ExactInputParams calldata params\r\n    ) external payable returns (uint amountOut);\r\n}\r\n\r\ninterface IBalancerVault {\r\n    function batchSwap(\r\n        SwapKind kind,\r\n        BatchSwapStep[] memory swaps,\r\n        IAsset[] memory assets,\r\n        FundManagement memory funds,\r\n        int256[] memory limits,\r\n        uint256 deadline\r\n    ) external returns (int256[] memory assetDeltas);\r\n\r\n    struct BatchSwapStep {\r\n        bytes32 poolId;\r\n        uint256 assetInIndex;\r\n        uint256 assetOutIndex;\r\n        uint256 amount;\r\n        bytes userData;\r\n    }\r\n\r\n    enum SwapKind { GIVEN_IN, GIVEN_OUT }\r\n\r\n    struct FundManagement {\r\n        address sender;\r\n        bool fromInternalBalance;\r\n        address payable recipient;\r\n        bool toInternalBalance;\r\n    }\r\n}\r\n\r\ninterface ICurveStableSwapNG {\r\n    function exchange(\r\n        int128 i, \r\n        int128 j, \r\n        uint256 dx, \r\n        uint256 min_dy,\r\n        address _receiver\r\n    ) external returns (uint256);\r\n\r\n    function coins(uint256 i) external view returns (address);\r\n}\r\n\r\ninterface ICurveRouter {\r\n    function exchange(\r\n        address[11] memory _route,\r\n        uint256[5][5] memory _swap_params,\r\n        uint256 _amount,\r\n        uint256 _expected,\r\n        address[5] memory _pools\r\n    ) external returns (uint256);\r\n}\r\n\r\ncontract AirPuffHandlerM is OwnableUpgradeable, ReentrancyGuardUpgradeable, PausableUpgradeable {\r\n    using SafeERC20Upgradeable for IERC20Upgradeable;\r\n    using MathUpgradeable for uint256;\r\n    using MathUpgradeable for uint128;\r\n\r\n    address public keeper;\r\n    bytes32 public balancerLRTAssetPool;\r\n    bytes32 public balancerMixedLRTPool;\r\n    address public LRTAsset;\r\n    uint24 public uniFee;\r\n    uint256 public balancerDeadline;\r\n\r\n    struct SwapHandlerAddresses {\r\n        address BalancerVault;\r\n        address WETH;\r\n        address Univ3Router;\r\n    }\r\n\r\n    struct FundManagement {\r\n        address sender;\r\n        bool fromInternalBalance;\r\n        address payable recipient;\r\n        bool toInternalBalance;\r\n    }\r\n\r\n    struct BatchSwapStep {\r\n        bytes32 poolId;\r\n        uint256 assetInIndex;\r\n        uint256 assetOutIndex;\r\n        uint256 amount;\r\n        bytes userData;\r\n    }\r\n\r\n    struct InterestRateConfig {\r\n        uint256 CEIL_SLOPE_1;\r\n        uint256 CEIL_SLOPE_2;\r\n        uint256 MAX_INTEREST_SLOPE_1;\r\n        uint256 MAX_INTEREST_SLOPE_2;\r\n        uint256 baseInterestRate;\r\n    }\r\n\r\n    struct RateSnapshot {\r\n        uint256 rate;\r\n        uint256 timestamp;\r\n        uint256 snapshotID;\r\n        uint256 closeTimestamp;\r\n    }\r\n    struct CurvePools {\r\n        address[5] curvePoolsIn;\r\n        address[5] curvePoolsOut;\r\n    }\r\n\r\n    struct CurvePoolsSwapPaths {\r\n        uint256[5][5] swapPathsIn;\r\n        uint256[5][5] swapPathsOut;\r\n    }\r\n\r\n    struct CurveRouterSwapPath {\r\n        address[11] routeIn;\r\n        address[11] routeOut;\r\n    }\r\n\r\n    SwapHandlerAddresses public swapHandlerAddresses;\r\n    InterestRateConfig public interestRateConfig;\r\n\r\n    mapping(address => bool) public allowedVaults;\r\n    mapping(address => address) public chainlinkOracle;\r\n    mapping(address => mapping(uint256 => RateSnapshot)) public rateSnapshots;\r\n    mapping(address => uint256) public vaultCurrentSnapshotID;\r\n    mapping(address => address) public StrategyToLRT;\r\n    \r\n    uint256[50] private __gaps;\r\n    mapping(address => address) public StrategyToCurvePool;\r\n    mapping(address => bytes32) public balancerInPoolID;\r\n    mapping(address => bytes32) public balancerOutPoolID;\r\n    mapping(address => CurveRouterSwapPath) internal curveRouterSwapPath;\r\n    mapping(address => CurvePools) internal curvePools;\r\n    mapping(address => CurvePoolsSwapPaths) internal curvePoolsSwapPaths;\r\n    mapping(address => bool) public strategyIsRouterPath;\r\n    address public CurveRouter;\r\n    uint256 public uniswapSlippage;\r\n    address public UniswapQuoter;\r\n    address public VectorOracle;\r\n    mapping(address => bool) public isVectorStrategy;\r\n    mapping(address => bool) public hasDecimals;\r\n\r\n    event HandlerAddressesChanged(address _Kyber);\r\n    event RequestFulfilled(address indexed user, uint256 openAmount, uint256 closedAmount);\r\n    event InterestParamsChanged(uint256 ceilSlope1, uint256 ceilSlope2, uint256 maxInterestSlope1, uint256 maxInterestSlope2, uint256 baseInterestRate);\r\n    event ChainlinkOracleSet(address token, address oracle);\r\n    event SnapshotTaken();\r\n    event SetKeeper(address indexed keeper);\r\n    event PoolIDSet(bytes32 balancerLRTAssetPool, bytes32 balancerMixedLRTPool);\r\n    event VaultToLRTAssetSet(address indexed strategy, address indexed LRTAsset);\r\n    event UniFeeChanged(uint24 uniFee);\r\n    event BalancerDeadlineSet(uint256 balancerDeadline);\r\n    event StrategyToCurvePoolSet(address indexed strategy, address indexed curvePool);\r\n    event StrategyToCurvePoolsInSet(\r\n        address indexed strategy,\r\n        address[5] curvePoolIn,\r\n        address[5] curvePoolOut\r\n    );\r\n    event CurveRouterSet(address indexed CurveRouter);\r\n    event StrategyRouterSet(address indexed strategy, address[11] routerSwapPathIn, address[11] routerSwapPathOut);\r\n    event SwapPathSet(address indexed strategy, uint256[5][5] swappathIn, uint256[5][5] swappathOut);\r\n    event UniswapSlippageSet(uint256 slippage);\r\n    event TokenHasDecimalsSet(address token, bool hasDecimals);\r\n\r\n    modifier onlyKeeper() {\r\n        require(msg.sender == keeper, \"Only Keeper\");\r\n        _;\r\n    }\r\n\r\n    /// @custom:oz-upgrades-unsafe-allow constructor\r\n    constructor() {\r\n        _disableInitializers();\r\n    }\r\n\r\n    function initialize() external initializer {\r\n\r\n        interestRateConfig.baseInterestRate = 5e16;\r\n        interestRateConfig.CEIL_SLOPE_1 = 8e17;\r\n        interestRateConfig.CEIL_SLOPE_2 = 1e18;\r\n        interestRateConfig.MAX_INTEREST_SLOPE_1 = 1e17;\r\n        interestRateConfig.MAX_INTEREST_SLOPE_2 = 3e17;\r\n        uniFee = 500;\r\n\r\n        __Ownable_init();\r\n        __Pausable_init();\r\n        __ReentrancyGuard_init();\r\n    }\r\n\r\n    function setHasDecimals(address _token, bool _hasDecimals) external onlyOwner {\r\n        hasDecimals[_token] = _hasDecimals;\r\n        emit TokenHasDecimalsSet(_token, _hasDecimals);\r\n    }\r\n\r\n    function setIsVectorStrategy(address _strategy,bool _isVector) external onlyOwner {\r\n        isVectorStrategy[_strategy] = _isVector;\r\n    }\r\n\r\n    function setVectorOracle(address _VectorOracle) external onlyOwner {\r\n        require(_VectorOracle != address(0), \"Zero address\");\r\n        VectorOracle = _VectorOracle;\r\n    }\r\n\r\n    // -- Setters --//\r\n    //10 for 1% slippage\r\n    function setUniswapSlippage(uint256 _slippage) external onlyOwner {\r\n        // max 10% slippage\r\n        require(_slippage <= 100, \"Invalid slippage\");\r\n        uniswapSlippage = _slippage;\r\n        emit UniswapSlippageSet(_slippage);\r\n    }\r\n\r\n    function setStrategyToCurvePool(address _strategy, address _curvePool) external onlyOwner {\r\n        StrategyToCurvePool[_strategy] = _curvePool;\r\n        emit StrategyToCurvePoolSet(_strategy, _curvePool);\r\n    }\r\n\r\n    function setBalancerDeadline(uint256 _balancerDeadline) external onlyOwner {\r\n        balancerDeadline = _balancerDeadline;\r\n        emit BalancerDeadlineSet(_balancerDeadline);\r\n    }\r\n\r\n    function setUniFee(uint24 _uniFee) external onlyOwner {\r\n        uniFee = _uniFee;\r\n        emit UniFeeChanged(_uniFee);\r\n    }\r\n\r\n    function setVaultToLRT(address _strategy, address _LRT) public onlyOwner {\r\n        StrategyToLRT[_strategy] = _LRT;\r\n        emit VaultToLRTAssetSet(_strategy, _LRT);\r\n    }\r\n\r\n    function setStrategyPoolID(bytes32 _balancerPoolIn, bytes32 _balancerPoolOut, address _strategy) public onlyOwner {\r\n        balancerInPoolID[_strategy] = _balancerPoolIn;\r\n        balancerOutPoolID[_strategy] = _balancerPoolOut;\r\n        emit PoolIDSet(_balancerPoolIn, _balancerPoolOut);\r\n    }\r\n\r\n    function setKeeper(address _keeper) public onlyOwner {\r\n        require(_keeper != address(0), \"Zero address\");\r\n        keeper = _keeper;\r\n        emit SetKeeper(_keeper);\r\n    }\r\n\r\n    function setSwapHandlerAddresses(\r\n        address _BalancerVault,\r\n        address _WETH,\r\n        address _Univ3Router\r\n    ) external onlyOwner {\r\n        swapHandlerAddresses.BalancerVault = _BalancerVault;\r\n        swapHandlerAddresses.WETH = _WETH;\r\n        swapHandlerAddresses.Univ3Router = _Univ3Router;\r\n        emit HandlerAddressesChanged(_BalancerVault);\r\n    }\r\n\r\n    function setAllowedVault(address _vault, bool _allowed) external onlyOwner {\r\n        require(_vault != address(0), \"Vault address cannot be 0\");\r\n        allowedVaults[_vault] = _allowed;\r\n    }\r\n\r\n    function setChainlinkOracleForAsset(address _token, address _oracle) external onlyOwner {\r\n        require(_token != address(0), \"Zero address\");\r\n        chainlinkOracle[_token] = _oracle;\r\n        emit ChainlinkOracleSet(_token, _oracle);\r\n    }\r\n\r\n    function setInterestRate(\r\n        uint256 _ceilSlope1,\r\n        uint256 _ceilSlope2,\r\n        uint256 _maxInterestSlope1,\r\n        uint256 _maxInterestSlope2,\r\n        uint256 _baseInterestRate\r\n    ) external onlyOwner {\r\n        require(_ceilSlope1 < _ceilSlope2, \"Invalid ceilSlope1 and ceilSlope2\");\r\n        require(_maxInterestSlope1 < _maxInterestSlope2, \"Invalid maxInterestSlope1 and maxInterestSlope2\");\r\n        interestRateConfig.CEIL_SLOPE_1 = _ceilSlope1;\r\n        interestRateConfig.CEIL_SLOPE_2 = _ceilSlope2;\r\n        interestRateConfig.MAX_INTEREST_SLOPE_1 = _maxInterestSlope1;\r\n        interestRateConfig.MAX_INTEREST_SLOPE_2 = _maxInterestSlope2;\r\n        interestRateConfig.baseInterestRate = _baseInterestRate;\r\n        emit InterestParamsChanged(_ceilSlope1, _ceilSlope2, _maxInterestSlope1, _maxInterestSlope2, _baseInterestRate);\r\n    }\r\n\r\n    function setStrategyRouterSwapPath(\r\n        address _strategy,\r\n        address[11] memory _routerSwapPathIn,\r\n        address[11] memory _routerSwapPathOut\r\n    ) external onlyOwner {\r\n        curveRouterSwapPath[_strategy] = CurveRouterSwapPath(_routerSwapPathIn, _routerSwapPathOut);\r\n        strategyIsRouterPath[_strategy] = true;\r\n        emit StrategyRouterSet(_strategy, _routerSwapPathIn, _routerSwapPathOut);\r\n    }\r\n\r\n    function setCurveRouter(address _CurveRouter) external onlyOwner {\r\n        require(_CurveRouter != address(0), \"Zero address\");\r\n        CurveRouter = _CurveRouter;\r\n        emit CurveRouterSet(_CurveRouter);\r\n    }\r\n\r\n    function setStrategyToCurvePools(\r\n        address _strategy,\r\n        address[5] memory _curvePoolsIn,\r\n        address[5] memory _curvePoolOut\r\n    ) external onlyOwner {\r\n        curvePools[_strategy] = CurvePools(_curvePoolsIn, _curvePoolOut);\r\n        emit StrategyToCurvePoolsInSet(_strategy, _curvePoolsIn, _curvePoolOut);\r\n    }\r\n\r\n    function setCurvePoolsSwapPaths(\r\n        address _strategy,\r\n        uint256[5][5] memory _swapPathIn,\r\n        uint256[5][5] memory _swapPathOut\r\n    ) external onlyOwner {\r\n        curvePoolsSwapPaths[_strategy] = CurvePoolsSwapPaths(_swapPathIn, _swapPathOut);\r\n        emit SwapPathSet(_strategy, _swapPathIn, _swapPathOut);\r\n    }\r\n\r\n    //-- View functions --//\r\n    function getCurveInAndOutPools(\r\n        address _strategy\r\n    ) external view returns (CurvePools memory) {\r\n        return curvePools[_strategy];\r\n    }\r\n\r\n    function getCurveRouterSwapPath(address _strategy) external view returns (CurveRouterSwapPath memory) {\r\n        return curveRouterSwapPath[_strategy];\r\n    }\r\n\r\n    function getCurvePoolsSwapPaths(\r\n        address _strategy\r\n    ) external view returns (CurvePoolsSwapPaths memory) {\r\n        return curvePoolsSwapPaths[_strategy];\r\n    }\r\n\r\n    function getUserInfo(address _user, uint256 _positionID, address _AirPuffVault) public view returns (IAirPuffVaultM.UserInfo memory) {\r\n        return IAirPuffVaultM(_AirPuffVault).userInfo(_user,_positionID);\r\n    }\r\n\r\n    function getUserTimestamp(address _user, uint256 _positionID, address _AirPuffVault) public view returns (IAirPuffVaultM.PositionTimestamps memory) {\r\n        return IAirPuffVaultM(_AirPuffVault).positionTimestamps(_user,_positionID);\r\n    }\r\n\r\n    function getPositionWithInterestRate(address _user, uint256 _positionID, address _AirPuffVault) public view returns (uint256,uint256) {\r\n        require(allowedVaults[_AirPuffVault], 'Not an allowed vault');\r\n        IAirPuffVaultM.UserInfo memory _userInfo = getUserInfo(_user, _positionID, _AirPuffVault);\r\n        IAirPuffVaultM.PositionTimestamps memory _positionTimestamps = getUserTimestamp(_user, _positionID, _AirPuffVault);\r\n\r\n        uint256 timestamp = _positionTimestamps.openTimestamp;\r\n        address positionLendingVault = IAirPuffVaultM(_AirPuffVault).LendingVault();\r\n        \r\n        uint256 positionAmount = _userInfo.leverageAmount;\r\n        uint256 positionEnteredSnapshot = _positionTimestamps.vaultSnapshotID;\r\n        uint256 currentSnapshot = vaultCurrentSnapshotID[positionLendingVault];\r\n        uint256 accruedInterests;\r\n\r\n        for (uint256 i = positionEnteredSnapshot; i <= currentSnapshot; i++) {\r\n            \r\n            RateSnapshot memory rs = rateSnapshots[positionLendingVault][i];\r\n            RateSnapshot memory rsAdd = rateSnapshots[positionLendingVault][i+1];\r\n\r\n            uint256 interests = rs.rate;\r\n            if (i != currentSnapshot){\r\n                uint256 timeElapsed;\r\n                if(i == positionEnteredSnapshot){\r\n                    timeElapsed = rsAdd.timestamp - timestamp;\r\n                } else {\r\n                    timeElapsed = rsAdd.timestamp - rs.timestamp;\r\n                }\r\n\r\n                accruedInterests += interests * timeElapsed / 365 days;\r\n            } else {\r\n                uint256 timeElapsed;\r\n                if (i == positionEnteredSnapshot) {\r\n                    timeElapsed = block.timestamp - timestamp;\r\n                } else {\r\n                    timeElapsed = block.timestamp - rs.timestamp;\r\n                }\r\n                accruedInterests += interests * timeElapsed / 365 days;\r\n            }\r\n        }\r\n        // @note The USDC vault has 6 decimals\r\n        uint256 posDebtValueWithInterests = positionAmount * (1e18 + accruedInterests) / 1e18;\r\n        uint256 totalInterests = posDebtValueWithInterests - positionAmount;\r\n        \r\n        return (posDebtValueWithInterests, totalInterests);\r\n    }\r\n\r\n    function getLatestData(address _token) public view returns (uint256) {\r\n        (, /* uint80 roundID */ int answer /*uint startedAt*/ /*uint timeStamp*/ /*uint80 answeredInRound*/, , , ) = AggregatorV3Interface(\r\n            chainlinkOracle[_token]\r\n        ).latestRoundData(); //in 1e8\r\n\r\n        uint256 decimals = AggregatorV3Interface(chainlinkOracle[_token]).decimals();\r\n        if(decimals != 18) {\r\n            return uint256(answer) * 10**(18 - decimals);\r\n        } else {\r\n            return uint256(answer);\r\n\r\n        }\r\n    }\r\n\r\n    function getAnyAssetPrice(address _token, address _strategy) public view returns (uint256) {\r\n        if (chainlinkOracle[_token] != address(0)) {\r\n            uint256 chPrice = getLatestData(_token);\r\n            return chPrice;\r\n        } else {\r\n            uint256 finalPrice;\r\n            if (isVectorStrategy[_strategy]) {\r\n                finalPrice = IVectorOracle(VectorOracle).consultvETHPrice();\r\n            } else {\r\n                address assetToOracle;\r\n                try IAirPuffVaultM(_strategy).strategyAddresses() {\r\n                    IAirPuffVaultM.StrategyAddresses memory sa = IAirPuffVaultM(_strategy).strategyAddresses();\r\n                    assetToOracle = sa.API3Oracle;\r\n                    (int224 price,) = IAPI3Oracle(assetToOracle).read();\r\n                    uint256 LRTAssetPrice = abi.decode(abi.encode(price), (uint256));\r\n                    finalPrice = LRTAssetPrice;\r\n                } catch {\r\n                    revert(\"No oracle set for this strategy\");\r\n                }\r\n            }\r\n\r\n            return finalPrice;\r\n        }\r\n    }\r\n\r\n    function getAnySlippagedAmountOut(address _assetFrom, address _to, uint256 _amount, address _strategy, bool _close) public view returns (uint256) {\r\n        uint256 assetOutPrice;\r\n\r\n        if (isVectorStrategy[_strategy]) {\r\n            assetOutPrice = IVectorOracle(VectorOracle).consultvETHPrice();\r\n        } else {\r\n            if (!_close) {\r\n                assetOutPrice = getAnyAssetPrice(_to, _strategy);\r\n            } else {\r\n                assetOutPrice = getAnyAssetPrice(_assetFrom, _strategy);\r\n            }\r\n        }\r\n        \r\n        uint256 pricedInAssetAmount;\r\n        uint256 amountOutMin;\r\n        if (assetOutPrice != 0) {\r\n            if (!_close) {\r\n                pricedInAssetAmount = _amount * 1e18 / assetOutPrice;\r\n                amountOutMin = pricedInAssetAmount - (pricedInAssetAmount * uniswapSlippage / 1000);\r\n            } else {\r\n                pricedInAssetAmount = _amount * assetOutPrice / 1e18;\r\n                amountOutMin = pricedInAssetAmount - (pricedInAssetAmount * uniswapSlippage / 1000);\r\n            }\r\n\r\n            if (hasDecimals[_to]) {\r\n                amountOutMin = amountOutMin / (10 ** (18-IWETH(_to).decimals()));\r\n            }\r\n            \r\n            return amountOutMin;\r\n        } else {\r\n            return 0;\r\n        }\r\n    }\r\n\r\n    function getInterestRate(address _lendingVault) public view returns (uint256) {\r\n        uint256 utilRate = ILending(_lendingVault).getUtilizationRate();\r\n        uint256 interestRatePercent;\r\n        if (utilRate <= interestRateConfig.CEIL_SLOPE_1) {\r\n            interestRatePercent =  interestRateConfig.baseInterestRate + (1e18 - (interestRateConfig.CEIL_SLOPE_1 - utilRate)) * interestRateConfig.MAX_INTEREST_SLOPE_1 /1e18;\r\n        } else {\r\n            interestRatePercent = (interestRateConfig.baseInterestRate + interestRateConfig.MAX_INTEREST_SLOPE_1 +\r\n                ((utilRate - interestRateConfig.CEIL_SLOPE_1) * (interestRateConfig.MAX_INTEREST_SLOPE_2 - interestRateConfig.MAX_INTEREST_SLOPE_1)) /\r\n                (interestRateConfig.CEIL_SLOPE_2 - interestRateConfig.CEIL_SLOPE_1));\r\n        }\r\n        return interestRatePercent;\r\n    }\r\n\r\n    // -- Admin functions --//\r\n\r\n    function takeInterestsSnapshot(address _AirPuffVault) public onlyKeeper {\r\n        require(allowedVaults[_AirPuffVault], 'Not an allowed vault');\r\n        address lendingVault = IAirPuffVaultM(_AirPuffVault).LendingVault();\r\n        vaultCurrentSnapshotID[lendingVault]++;\r\n        RateSnapshot storage rs = rateSnapshots[lendingVault][vaultCurrentSnapshotID[lendingVault]];\r\n        uint256 interestRate = getInterestRate(lendingVault);\r\n        rs.rate = interestRate;\r\n        rs.snapshotID = vaultCurrentSnapshotID[lendingVault];\r\n        rs.timestamp = block.timestamp;\r\n\r\n        emit SnapshotTaken();\r\n    }\r\n\r\n    // -- Reserved functions --//\r\n\r\n    function handlerSwap(bool _isSimple,uint256 _amount,address _assetFrom,address _assetTo, bool _isClose, bool _isBalancer) external returns (uint256){\r\n        require(allowedVaults[msg.sender], 'Not an allowed vault');\r\n        uint256 amountOut;\r\n\r\n        if (StrategyToCurvePool[msg.sender] != address(0)) {\r\n            if (strategyIsRouterPath[msg.sender]) {\r\n                amountOut = _curveRouterSwapWithPaths(_amount, _isClose, _assetTo, _assetFrom);\r\n            } else {\r\n                amountOut = _curveSimpleSwap(_assetFrom, _amount, _assetTo, _isClose);\r\n            }\r\n            \r\n        } else {\r\n            if (_isBalancer) {\r\n                if (_isSimple) {\r\n                    amountOut = _swapBalancerSimple(_amount, _assetFrom, _assetTo, _isClose);\r\n                } else {\r\n                    amountOut = _swapBalancerMulti(_amount, _assetFrom, _assetTo, _isClose);\r\n                }\r\n            } else {\r\n                amountOut = _uniswapExecution(_amount, _assetFrom, _assetTo, _isClose);\r\n            }\r\n        }\r\n       \r\n        return amountOut;\r\n    }\r\n    \r\n    function _curveSimpleSwap(\r\n        address _assetFrom,\r\n        uint256 dx,\r\n        address _assetTo,\r\n        bool _isClose\r\n    ) internal returns (uint256 dy) {\r\n        require(StrategyToCurvePool[msg.sender] != address(0), 'No curve pool set for this strategy');\r\n        address curvePool = StrategyToCurvePool[msg.sender];\r\n\r\n        address asset0 = ICurveStableSwapNG(StrategyToCurvePool[msg.sender]).coins(0);\r\n        int128 i;\r\n        int128 j;\r\n        if (asset0 == _assetFrom) {\r\n            i = 0;\r\n            j = 1;\r\n        } else {\r\n            i = 1;\r\n            j = 0;\r\n        }\r\n\r\n        IERC20Upgradeable(_assetFrom).approve(curvePool, dx);\r\n\r\n        uint256 amountOutMin = getAnySlippagedAmountOut(_assetFrom, _assetTo, dx, msg.sender, _isClose);\r\n        require(amountOutMin > 0, \"Slippage too high\");\r\n\r\n        dy = ICurveStableSwapNG(curvePool).exchange(i, j, dx, amountOutMin, msg.sender);\r\n        \r\n        return dy;\r\n    }\r\n\r\n    function _curveRouterSwapWithPaths( uint256 _amount, bool _isClose, address _assetTo, address _assetFrom) internal returns (uint256) {\r\n        address[11] memory route;\r\n        address[5] memory _curvePools;\r\n        uint256[5][5] memory swap_params;\r\n        if (!_isClose) {\r\n            require(\r\n                curvePools[msg.sender].curvePoolsIn.length > 0,\r\n                \"No curve pool/routes set for this strategy\"\r\n            );\r\n            route = curveRouterSwapPath[msg.sender].routeIn;\r\n            _curvePools = curvePools[msg.sender].curvePoolsIn;\r\n            swap_params = curvePoolsSwapPaths[msg.sender].swapPathsIn;\r\n        } else {\r\n            require(\r\n                curvePools[msg.sender].curvePoolsOut.length > 0,\r\n                \"No curve pool/routes set for this strategy\"\r\n            );\r\n            route = curveRouterSwapPath[msg.sender].routeOut;\r\n            _curvePools = curvePools[msg.sender].curvePoolsOut;\r\n            swap_params = curvePoolsSwapPaths[msg.sender].swapPathsOut;\r\n        }\r\n\r\n        uint256 balBefore = IERC20Upgradeable(_assetTo).balanceOf(\r\n            address(this)\r\n        );\r\n        IERC20Upgradeable(_assetFrom).approve(CurveRouter, _amount);\r\n\r\n        uint256 amountOutMin = getAnySlippagedAmountOut(_assetFrom, _assetTo, _amount, msg.sender, _isClose);\r\n        require(amountOutMin > 0, \"Slippage too high\");\r\n\r\n        ICurveRouter(CurveRouter).exchange(\r\n            route,\r\n            swap_params,\r\n            _amount,\r\n            amountOutMin,\r\n            _curvePools\r\n        );\r\n        uint256 balAfter = IERC20Upgradeable(_assetTo).balanceOf(address(this));\r\n        uint256 amountOut = balAfter - balBefore;\r\n        IERC20Upgradeable(_assetTo).safeTransfer(msg.sender, amountOut);\r\n\r\n        return amountOut;\r\n    }\r\n\r\n\r\n    function _swapBalancerSimple(\r\n        uint256 _amount,\r\n        address _assetFrom,\r\n        address _assetTo,\r\n        bool _isClosed\r\n    ) internal returns (uint256) {\r\n        IERC20Upgradeable(_assetFrom).safeIncreaseAllowance(swapHandlerAddresses.BalancerVault, _amount);\r\n        uint256 amountOutMin = getAnySlippagedAmountOut(_assetFrom, _assetTo, _amount, msg.sender, _isClosed);\r\n        int256 encodedOut;\r\n        unchecked {\r\n            encodedOut = int256(amountOutMin);\r\n        }\r\n        \r\n        require(encodedOut > 0, \"Slippage too high\");\r\n\r\n        IBalancerVault.BatchSwapStep[] memory swaps = new IBalancerVault.BatchSwapStep[](1);\r\n        swaps[0] = IBalancerVault.BatchSwapStep({\r\n            poolId: balancerInPoolID[msg.sender], // First pool ID\r\n            assetInIndex: 0,\r\n            assetOutIndex: 1,\r\n            amount: _amount,\r\n            userData: \"0x\"\r\n        });\r\n\r\n        // Assuming 3 assets are involved: _assetFrom, LRTAsset, and _assetTo\r\n        IAsset[] memory assets = new IAsset[](2);\r\n        assets[0] = IAsset(_assetFrom);\r\n        assets[1] = IAsset(_assetTo);\r\n\r\n        IBalancerVault.FundManagement memory funds = IBalancerVault.FundManagement({\r\n            sender: address(this),\r\n            fromInternalBalance: false,\r\n            recipient: payable(msg.sender),\r\n            toInternalBalance: false\r\n        });\r\n\r\n        // Adjust limits to accommodate for the intermediary asset\r\n        int256[] memory limits = new int256[](2);\r\n        limits[0] = int256(_amount); // Maximum amount of `_assetFrom` to spend\r\n        limits[1] = -encodedOut; // Minimum amount of `_assetTo` to receive, set to -1 to not specify\r\n\r\n        // Perform the batch swap\r\n        int256[] memory assetDeltas = IBalancerVault(swapHandlerAddresses.BalancerVault).batchSwap(\r\n            IBalancerVault.SwapKind.GIVEN_IN,\r\n            swaps,\r\n            assets,\r\n            funds,\r\n            limits,\r\n            block.timestamp + balancerDeadline // deadline\r\n        );\r\n\r\n        // Assuming `assetDeltas[1]` will be negative, representing the amount of `_assetTo` received.\r\n        // Convert it to positive to return the amount out.\r\n        return uint256(-assetDeltas[1]);\r\n    }\r\n\r\n    function _swapBalancerMulti(\r\n        uint256 _amount,\r\n        address _assetFrom,\r\n        address _assetTo,\r\n        bool _isClose\r\n    ) internal returns (uint256) {\r\n        uint256 amountOutMin = getAnySlippagedAmountOut(_assetFrom, _assetTo, _amount, msg.sender, _isClose);\r\n        int256 encodedOut;\r\n        unchecked {\r\n            encodedOut = int256(amountOutMin);\r\n        }\r\n        require(encodedOut > 0, \"Slippage too high\");\r\n\r\n        IERC20Upgradeable(_assetFrom).safeIncreaseAllowance(swapHandlerAddresses.BalancerVault, _amount);\r\n        bytes32 poolID1;\r\n        bytes32 poolID2;\r\n        if (_isClose) {\r\n            poolID1 = balancerOutPoolID[msg.sender];\r\n            poolID2 = balancerInPoolID[msg.sender];\r\n        } else {\r\n            poolID1 = balancerInPoolID[msg.sender];\r\n            poolID2 = balancerOutPoolID[msg.sender];\r\n        }\r\n\r\n        IBalancerVault.BatchSwapStep[] memory swaps = new IBalancerVault.BatchSwapStep[](2);\r\n        swaps[0] = IBalancerVault.BatchSwapStep({\r\n            poolId: poolID1, // First pool ID\r\n            assetInIndex: 0,\r\n            assetOutIndex: 1,\r\n            amount: _amount,\r\n            userData: \"0x\"\r\n        });\r\n        swaps[1] = IBalancerVault.BatchSwapStep({\r\n            poolId: poolID2, // Second pool ID\r\n            assetInIndex: 1,\r\n            assetOutIndex: 2,\r\n            amount: 0, // for GIVEN_IN, amount is only relevant in the first step\r\n            userData: \"0x\"\r\n        });\r\n\r\n        // Assuming 3 assets are involved: _assetFrom, LRTAsset, and _assetTo\r\n        IAsset[] memory assets = new IAsset[](3);\r\n        assets[0] = IAsset(_assetFrom);\r\n        // This needs to be the intermediary asset; replace `LRTAsset` with the actual address\r\n        assets[1] = IAsset(StrategyToLRT[msg.sender]); \r\n        assets[2] = IAsset(_assetTo);\r\n\r\n        IBalancerVault.FundManagement memory funds = IBalancerVault.FundManagement({\r\n            sender: address(this),\r\n            fromInternalBalance: false,\r\n            recipient: payable(msg.sender),\r\n            toInternalBalance: false\r\n        });\r\n\r\n        // Adjust limits to accommodate for the intermediary asset\r\n        int256[] memory limits = new int256[](3);\r\n        limits[0] = int256(_amount); // Maximum amount of `_assetFrom` to spend\r\n        limits[1] = int256(0); // Set to 0 or another value based on your strategy for the intermediary asset\r\n        limits[2] = -encodedOut; // Minimum amount of `_assetTo` to receive, set to -1 to not specify\r\n\r\n        // Perform the batch swap\r\n        int256[] memory assetDeltas = IBalancerVault(swapHandlerAddresses.BalancerVault).batchSwap(\r\n            IBalancerVault.SwapKind.GIVEN_IN,\r\n            swaps,\r\n            assets,\r\n            funds,\r\n            limits,\r\n            block.timestamp + balancerDeadline // deadline\r\n        );\r\n\r\n        // Assuming `assetDeltas[2]` will be negative, representing the amount of `_assetTo` received.\r\n        // Convert it to positive to return the amount out.\r\n        return uint256(-assetDeltas[2]);\r\n    }\r\n\r\n    function _uniswapExecution(\r\n        uint256 _amount,\r\n        address _assetFrom,\r\n        address _assetTo,\r\n        bool _isClose\r\n    ) internal returns (uint256) {\r\n        IERC20Upgradeable(_assetFrom).approve(swapHandlerAddresses.Univ3Router, _amount);\r\n\r\n        uint256 amountOutMin = getAnySlippagedAmountOut(_assetFrom, _assetTo, _amount, msg.sender, _isClose);\r\n        require(amountOutMin > 0, \"Slippage too high\");\r\n\r\n        ISwapRouter.ExactInputSingleParams memory params = ISwapRouter\r\n            .ExactInputSingleParams({\r\n                tokenIn: _assetFrom,\r\n                tokenOut: _assetTo,\r\n                fee: uniFee,\r\n                recipient: msg.sender,\r\n                deadline: block.timestamp,\r\n                amountIn: _amount,\r\n                amountOutMinimum: amountOutMin,\r\n                sqrtPriceLimitX96: 0\r\n            });\r\n\r\n        uint256 amountOut = ISwapRouter(swapHandlerAddresses.Univ3Router).exactInputSingle(params);\r\n\r\n        return amountOut;\r\n    }\r\n\r\n    receive() external payable {}\r\n}"
      },
      "/var/www/html/boltfork/posley/AirPuff/contracts/interfaces/AggregatorV3Interface.sol": {
        "content": "// SPDX-License-Identifier: UNLICENSED\r\npragma solidity 0.8.21;\r\n\r\ninterface AggregatorV3Interface {\r\n    function decimals() external view returns (uint8);\r\n\r\n    function description() external view returns (string memory);\r\n\r\n    function version() external view returns (uint256);\r\n\r\n    function getRoundData(\r\n        uint80 _roundId\r\n    ) external view returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);\r\n\r\n    function latestRoundData()\r\n        external\r\n        view\r\n        returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);\r\n}"
      },
      "/var/www/html/boltfork/posley/AirPuff/contracts/interfaces/IAPI3Oracle.sol": {
        "content": "// SPDX-License-Identifier: UNLICENSED\r\npragma solidity 0.8.21;\r\n\r\ninterface IAPI3Oracle {\r\n        function read()\r\n        external\r\n        view\r\n        returns (int224 value, uint32 timestamp);\r\n        function getExchangeRate() external view returns (uint256);\r\n}"
      },
      "/var/www/html/boltfork/posley/AirPuff/contracts/interfaces/IAirPuffVaultM.sol": {
        "content": "// SPDX-License-Identifier: UNLICENSED\r\npragma solidity 0.8.21;\r\n\r\ninterface IAirPuffVaultM {\r\n    struct UserInfo {\r\n        address user;\r\n        uint256 deposit;\r\n        uint256 leverage;\r\n        uint256 position;\r\n        bool liquidated;\r\n        address liquidator;\r\n        uint256 leverageAmount;\r\n        uint256 positionId;\r\n        bool closed;\r\n    }\r\n\r\n    struct PositionTimestamps {\r\n        uint256 openTimestamp;\r\n        uint256 closeTimestamp;\r\n        uint256 vaultSnapshotID;\r\n    }\r\n\r\n    function getAllLendingVaults() external view returns (address[] memory);\r\n    function userInfo(address _user,uint256 _positionID) external view returns (UserInfo memory);\r\n    function positionTimestamps(address _user,uint256 _positionID) external view returns (PositionTimestamps memory);\r\n    function LendingVault() external view returns (address);\r\n    function strategyAddresses() external view returns (StrategyAddresses memory);\r\n\r\n    struct StrategyAddresses {\r\n        address LRTAsset;\r\n        address WETH;\r\n        address API3Oracle;\r\n        address AirPuffHandler;\r\n        address borrowAsset;\r\n    }\r\n}"
      },
      "/var/www/html/boltfork/posley/AirPuff/contracts/interfaces/ILending.sol": {
        "content": "//SPDX-License-Identifier: UNLICENSED\r\npragma solidity 0.8.21;\r\n\r\ninterface ILending {\r\n    function lend(uint256 _borrowed, address _receiver) external returns (bool status);\r\n\r\n    function repayDebt(uint256 leverage, uint256 debtValue) external returns (bool);\r\n\r\n    function getTotalDebt() external view returns (uint256);\r\n\r\n    function updateTotalDebt(uint256 profit) external returns (uint256);\r\n\r\n    function totalAssets() external view returns (uint256);\r\n\r\n    function totalDebt() external view returns (uint256);\r\n\r\n    function balanceOfUSDC() external view returns (uint256);\r\n\r\n    function getUtilizationRate() external view returns (uint256);\r\n}\r\n"
      },
      "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/ContextUpgradeable.sol\";\nimport {Initializable} from \"../proxy/utils/Initializable.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 OwnableUpgradeable is Initializable, ContextUpgradeable {\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    function __Ownable_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable_init_unchained() internal onlyInitializing {\n        _transferOwnership(_msgSender());\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _checkOwner();\n        _;\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 the sender is not the owner.\n     */\n    function _checkOwner() internal view virtual {\n        require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby disabling 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    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)\n\npragma solidity ^0.8.2;\n\nimport \"../../utils/AddressUpgradeable.sol\";\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 proxied contracts do not make use of 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 * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be\n * reused. This mechanism prevents re-execution of each \"step\" but allows the creation of new initialization steps in\n * case an upgrade adds a module that needs to be initialized.\n *\n * For example:\n *\n * [.hljs-theme-light.nopadding]\n * ```solidity\n * contract MyToken is ERC20Upgradeable {\n *     function initialize() initializer public {\n *         __ERC20_init(\"MyToken\", \"MTK\");\n *     }\n * }\n *\n * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {\n *     function initializeV2() reinitializer(2) public {\n *         __ERC20Permit_init(\"MyToken\");\n *     }\n * }\n * ```\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 *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\n * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() {\n *     _disableInitializers();\n * }\n * ```\n * ====\n */\nabstract contract Initializable {\n    /**\n     * @dev Indicates that the contract has been initialized.\n     * @custom:oz-retyped-from bool\n     */\n    uint8 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 Triggered when the contract has been initialized or reinitialized.\n     */\n    event Initialized(uint8 version);\n\n    /**\n     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\n     * `onlyInitializing` functions can be used to initialize parent contracts.\n     *\n     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a\n     * constructor.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier initializer() {\n        bool isTopLevelCall = !_initializing;\n        require(\n            (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),\n            \"Initializable: contract is already initialized\"\n        );\n        _initialized = 1;\n        if (isTopLevelCall) {\n            _initializing = true;\n        }\n        _;\n        if (isTopLevelCall) {\n            _initializing = false;\n            emit Initialized(1);\n        }\n    }\n\n    /**\n     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the\n     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be\n     * used to initialize parent contracts.\n     *\n     * A reinitializer may be used after the original initialization step. This is essential to configure modules that\n     * are added through upgrades and that require initialization.\n     *\n     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`\n     * cannot be nested. If one is invoked in the context of another, execution will revert.\n     *\n     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\n     * a contract, executing them in the right order is up to the developer or operator.\n     *\n     * WARNING: setting the version to 255 will prevent any future reinitialization.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier reinitializer(uint8 version) {\n        require(!_initializing && _initialized < version, \"Initializable: contract is already initialized\");\n        _initialized = version;\n        _initializing = true;\n        _;\n        _initializing = false;\n        emit Initialized(version);\n    }\n\n    /**\n     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n     * {initializer} and {reinitializer} modifiers, directly or indirectly.\n     */\n    modifier onlyInitializing() {\n        require(_initializing, \"Initializable: contract is not initializing\");\n        _;\n    }\n\n    /**\n     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\n     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\n     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\n     * through proxies.\n     *\n     * Emits an {Initialized} event the first time it is successfully executed.\n     */\n    function _disableInitializers() internal virtual {\n        require(!_initializing, \"Initializable: contract is initializing\");\n        if (_initialized != type(uint8).max) {\n            _initialized = type(uint8).max;\n            emit Initialized(type(uint8).max);\n        }\n    }\n\n    /**\n     * @dev Returns the highest version that has been initialized. See {reinitializer}.\n     */\n    function _getInitializedVersion() internal view returns (uint8) {\n        return _initialized;\n    }\n\n    /**\n     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.\n     */\n    function _isInitializing() internal view returns (bool) {\n        return _initializing;\n    }\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/ContextUpgradeable.sol\";\nimport {Initializable} from \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Contract module which allows children to implement an emergency stop\n * mechanism that can be triggered by an authorized account.\n *\n * This module is used through inheritance. It will make available the\n * modifiers `whenNotPaused` and `whenPaused`, which can be applied to\n * the functions of your contract. Note that they will not be pausable by\n * simply including this module, only once the modifiers are put in place.\n */\nabstract contract PausableUpgradeable is Initializable, ContextUpgradeable {\n    /**\n     * @dev Emitted when the pause is triggered by `account`.\n     */\n    event Paused(address account);\n\n    /**\n     * @dev Emitted when the pause is lifted by `account`.\n     */\n    event Unpaused(address account);\n\n    bool private _paused;\n\n    /**\n     * @dev Initializes the contract in unpaused state.\n     */\n    function __Pausable_init() internal onlyInitializing {\n        __Pausable_init_unchained();\n    }\n\n    function __Pausable_init_unchained() internal onlyInitializing {\n        _paused = false;\n    }\n\n    /**\n     * @dev Modifier to make a function callable only when the contract is not paused.\n     *\n     * Requirements:\n     *\n     * - The contract must not be paused.\n     */\n    modifier whenNotPaused() {\n        _requireNotPaused();\n        _;\n    }\n\n    /**\n     * @dev Modifier to make a function callable only when the contract is paused.\n     *\n     * Requirements:\n     *\n     * - The contract must be paused.\n     */\n    modifier whenPaused() {\n        _requirePaused();\n        _;\n    }\n\n    /**\n     * @dev Returns true if the contract is paused, and false otherwise.\n     */\n    function paused() public view virtual returns (bool) {\n        return _paused;\n    }\n\n    /**\n     * @dev Throws if the contract is paused.\n     */\n    function _requireNotPaused() internal view virtual {\n        require(!paused(), \"Pausable: paused\");\n    }\n\n    /**\n     * @dev Throws if the contract is not paused.\n     */\n    function _requirePaused() internal view virtual {\n        require(paused(), \"Pausable: not paused\");\n    }\n\n    /**\n     * @dev Triggers stopped state.\n     *\n     * Requirements:\n     *\n     * - The contract must not be paused.\n     */\n    function _pause() internal virtual whenNotPaused {\n        _paused = true;\n        emit Paused(_msgSender());\n    }\n\n    /**\n     * @dev Returns to normal state.\n     *\n     * Requirements:\n     *\n     * - The contract must be paused.\n     */\n    function _unpause() internal virtual whenPaused {\n        _paused = false;\n        emit Unpaused(_msgSender());\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)\n\npragma solidity ^0.8.0;\nimport {Initializable} from \"../proxy/utils/Initializable.sol\";\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 ReentrancyGuardUpgradeable is Initializable {\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    function __ReentrancyGuard_init() internal onlyInitializing {\n        __ReentrancyGuard_init_unchained();\n    }\n\n    function __ReentrancyGuard_init_unchained() internal onlyInitializing {\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        _nonReentrantBefore();\n        _;\n        _nonReentrantAfter();\n    }\n\n    function _nonReentrantBefore() private {\n        // On the first call to nonReentrant, _status will be _NOT_ENTERED\n        require(_status != _ENTERED, \"ReentrancyGuard: reentrant call\");\n\n        // Any calls to nonReentrant after this point will fail\n        _status = _ENTERED;\n    }\n\n    function _nonReentrantAfter() private {\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    /**\n     * @dev Returns true if the reentrancy guard is currently set to \"entered\", which indicates there is a\n     * `nonReentrant` function in the call stack.\n     */\n    function _reentrancyGuardEntered() internal view returns (bool) {\n        return _status == _ENTERED;\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.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 IERC20Upgradeable {\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    /**\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(address from, address to, uint256 amount) external returns (bool);\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20PermitUpgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.4) (token/ERC20/extensions/IERC20Permit.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in\n * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].\n *\n * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by\n * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't\n * need to send a transaction, and thus is not required to hold Ether at all.\n *\n * ==== Security Considerations\n *\n * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature\n * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be\n * considered as an intention to spend the allowance in any specific way. The second is that because permits have\n * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should\n * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be\n * generally recommended is:\n *\n * ```solidity\n * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {\n *     try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}\n *     doThing(..., value);\n * }\n *\n * function doThing(..., uint256 value) public {\n *     token.safeTransferFrom(msg.sender, address(this), value);\n *     ...\n * }\n * ```\n *\n * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of\n * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also\n * {SafeERC20-safeTransferFrom}).\n *\n * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so\n * contracts should have entry points that don't rely on permit.\n */\ninterface IERC20PermitUpgradeable {\n    /**\n     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,\n     * given ``owner``'s signed approval.\n     *\n     * IMPORTANT: The same issues {IERC20-approve} has related to transaction\n     * ordering also apply here.\n     *\n     * Emits an {Approval} event.\n     *\n     * Requirements:\n     *\n     * - `spender` cannot be the zero address.\n     * - `deadline` must be a timestamp in the future.\n     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`\n     * over the EIP712-formatted function arguments.\n     * - the signature must use ``owner``'s current nonce (see {nonces}).\n     *\n     * For more information on the signature format, see the\n     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP\n     * section].\n     *\n     * CAUTION: See Security Considerations above.\n     */\n    function permit(\n        address owner,\n        address spender,\n        uint256 value,\n        uint256 deadline,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) external;\n\n    /**\n     * @dev Returns the current nonce for `owner`. This value must be\n     * included whenever a signature is generated for {permit}.\n     *\n     * Every successful call to {permit} increases ``owner``'s nonce by one. This\n     * prevents a signature from being used multiple times.\n     */\n    function nonces(address owner) external view returns (uint256);\n\n    /**\n     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.\n     */\n    // solhint-disable-next-line func-name-mixedcase\n    function DOMAIN_SEPARATOR() external view returns (bytes32);\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20Upgradeable.sol\";\nimport \"../extensions/IERC20PermitUpgradeable.sol\";\nimport \"../../../utils/AddressUpgradeable.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 SafeERC20Upgradeable {\n    using AddressUpgradeable for address;\n\n    /**\n     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,\n     * non-reverting calls are assumed to be successful.\n     */\n    function safeTransfer(IERC20Upgradeable token, address to, uint256 value) internal {\n        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));\n    }\n\n    /**\n     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the\n     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.\n     */\n    function safeTransferFrom(IERC20Upgradeable 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(IERC20Upgradeable 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        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    /**\n     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,\n     * non-reverting calls are assumed to be successful.\n     */\n    function safeIncreaseAllowance(IERC20Upgradeable token, address spender, uint256 value) internal {\n        uint256 oldAllowance = token.allowance(address(this), spender);\n        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));\n    }\n\n    /**\n     * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,\n     * non-reverting calls are assumed to be successful.\n     */\n    function safeDecreaseAllowance(IERC20Upgradeable 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            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));\n        }\n    }\n\n    /**\n     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,\n     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval\n     * to be set to zero before setting it to a non-zero value, such as USDT.\n     */\n    function forceApprove(IERC20Upgradeable token, address spender, uint256 value) internal {\n        bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);\n\n        if (!_callOptionalReturnBool(token, approvalCall)) {\n            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));\n            _callOptionalReturn(token, approvalCall);\n        }\n    }\n\n    /**\n     * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.\n     * Revert on invalid signature.\n     */\n    function safePermit(\n        IERC20PermitUpgradeable token,\n        address owner,\n        address spender,\n        uint256 value,\n        uint256 deadline,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) internal {\n        uint256 nonceBefore = token.nonces(owner);\n        token.permit(owner, spender, value, deadline, v, r, s);\n        uint256 nonceAfter = token.nonces(owner);\n        require(nonceAfter == nonceBefore + 1, \"SafeERC20: permit did not succeed\");\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(IERC20Upgradeable 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        require(returndata.length == 0 || abi.decode(returndata, (bool)), \"SafeERC20: ERC20 operation did not succeed\");\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     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.\n     */\n    function _callOptionalReturnBool(IERC20Upgradeable token, bytes memory data) private returns (bool) {\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 cannot use {Address-functionCall} here since this should return false\n        // and not revert is the subcall reverts.\n\n        (bool success, bytes memory returndata) = address(token).call(data);\n        return\n            success && (returndata.length == 0 || abi.decode(returndata, (bool))) && AddressUpgradeable.isContract(address(token));\n    }\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)\n\npragma solidity ^0.8.1;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary AddressUpgradeable {\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     * Furthermore, `isContract` will also return true if the target contract within\n     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,\n     * which only has an effect at the end of a transaction.\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://consensys.net/diligence/blog/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.8.0/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 functionCallWithValue(target, data, 0, \"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(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(\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        (bool success, bytes memory returndata) = target.call{value: value}(data);\n        return verifyCallResultFromTarget(target, 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        (bool success, bytes memory returndata) = target.staticcall(data);\n        return verifyCallResultFromTarget(target, 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        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\n     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\n     *\n     * _Available since v4.8._\n     */\n    function verifyCallResultFromTarget(\n        address target,\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        if (success) {\n            if (returndata.length == 0) {\n                // only check isContract if the call was successful and the return data is empty\n                // otherwise we already know that it was a contract\n                require(isContract(target), \"Address: call to non-contract\");\n            }\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    /**\n     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\n     * revert reason or 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            _revert(returndata, errorMessage);\n        }\n    }\n\n    function _revert(bytes memory returndata, string memory errorMessage) private pure {\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            /// @solidity memory-safe-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"
      },
      "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.4) (utils/Context.sol)\n\npragma solidity ^0.8.0;\nimport {Initializable} from \"../proxy/utils/Initializable.sol\";\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 ContextUpgradeable is Initializable {\n    function __Context_init() internal onlyInitializing {\n    }\n\n    function __Context_init_unchained() internal onlyInitializing {\n    }\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    function _contextSuffixLength() internal view virtual returns (uint256) {\n        return 0;\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[50] private __gap;\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/utils/math/MathUpgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Standard math utilities missing in the Solidity language.\n */\nlibrary MathUpgradeable {\n    enum Rounding {\n        Down, // Toward negative infinity\n        Up, // Toward infinity\n        Zero // Toward zero\n    }\n\n    /**\n     * @dev Returns the largest of two numbers.\n     */\n    function max(uint256 a, uint256 b) internal pure returns (uint256) {\n        return a > b ? a : b;\n    }\n\n    /**\n     * @dev Returns the smallest of two numbers.\n     */\n    function min(uint256 a, uint256 b) internal pure returns (uint256) {\n        return a < b ? a : b;\n    }\n\n    /**\n     * @dev Returns the average of two numbers. The result is rounded towards\n     * zero.\n     */\n    function average(uint256 a, uint256 b) internal pure returns (uint256) {\n        // (a + b) / 2 can overflow.\n        return (a & b) + (a ^ b) / 2;\n    }\n\n    /**\n     * @dev Returns the ceiling of the division of two numbers.\n     *\n     * This differs from standard division with `/` in that it rounds up instead\n     * of rounding down.\n     */\n    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {\n        // (a + b - 1) / b can overflow on addition, so we distribute.\n        return a == 0 ? 0 : (a - 1) / b + 1;\n    }\n\n    /**\n     * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0\n     * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)\n     * with further edits by Uniswap Labs also under MIT license.\n     */\n    function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {\n        unchecked {\n            // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use\n            // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256\n            // variables such that product = prod1 * 2^256 + prod0.\n            uint256 prod0; // Least significant 256 bits of the product\n            uint256 prod1; // Most significant 256 bits of the product\n            assembly {\n                let mm := mulmod(x, y, not(0))\n                prod0 := mul(x, y)\n                prod1 := sub(sub(mm, prod0), lt(mm, prod0))\n            }\n\n            // Handle non-overflow cases, 256 by 256 division.\n            if (prod1 == 0) {\n                // Solidity will revert if denominator == 0, unlike the div opcode on its own.\n                // The surrounding unchecked block does not change this fact.\n                // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.\n                return prod0 / denominator;\n            }\n\n            // Make sure the result is less than 2^256. Also prevents denominator == 0.\n            require(denominator > prod1, \"Math: mulDiv overflow\");\n\n            ///////////////////////////////////////////////\n            // 512 by 256 division.\n            ///////////////////////////////////////////////\n\n            // Make division exact by subtracting the remainder from [prod1 prod0].\n            uint256 remainder;\n            assembly {\n                // Compute remainder using mulmod.\n                remainder := mulmod(x, y, denominator)\n\n                // Subtract 256 bit number from 512 bit number.\n                prod1 := sub(prod1, gt(remainder, prod0))\n                prod0 := sub(prod0, remainder)\n            }\n\n            // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.\n            // See https://cs.stackexchange.com/q/138556/92363.\n\n            // Does not overflow because the denominator cannot be zero at this stage in the function.\n            uint256 twos = denominator & (~denominator + 1);\n            assembly {\n                // Divide denominator by twos.\n                denominator := div(denominator, twos)\n\n                // Divide [prod1 prod0] by twos.\n                prod0 := div(prod0, twos)\n\n                // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.\n                twos := add(div(sub(0, twos), twos), 1)\n            }\n\n            // Shift in bits from prod1 into prod0.\n            prod0 |= prod1 * twos;\n\n            // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such\n            // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for\n            // four bits. That is, denominator * inv = 1 mod 2^4.\n            uint256 inverse = (3 * denominator) ^ 2;\n\n            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works\n            // in modular arithmetic, doubling the correct bits in each step.\n            inverse *= 2 - denominator * inverse; // inverse mod 2^8\n            inverse *= 2 - denominator * inverse; // inverse mod 2^16\n            inverse *= 2 - denominator * inverse; // inverse mod 2^32\n            inverse *= 2 - denominator * inverse; // inverse mod 2^64\n            inverse *= 2 - denominator * inverse; // inverse mod 2^128\n            inverse *= 2 - denominator * inverse; // inverse mod 2^256\n\n            // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.\n            // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is\n            // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1\n            // is no longer required.\n            result = prod0 * inverse;\n            return result;\n        }\n    }\n\n    /**\n     * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.\n     */\n    function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {\n        uint256 result = mulDiv(x, y, denominator);\n        if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {\n            result += 1;\n        }\n        return result;\n    }\n\n    /**\n     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.\n     *\n     * Inspired by Henry S. Warren, Jr.'s \"Hacker's Delight\" (Chapter 11).\n     */\n    function sqrt(uint256 a) internal pure returns (uint256) {\n        if (a == 0) {\n            return 0;\n        }\n\n        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.\n        //\n        // We know that the \"msb\" (most significant bit) of our target number `a` is a power of 2 such that we have\n        // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.\n        //\n        // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`\n        // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`\n        // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`\n        //\n        // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.\n        uint256 result = 1 << (log2(a) >> 1);\n\n        // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,\n        // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at\n        // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision\n        // into the expected uint128 result.\n        unchecked {\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            return min(result, a / result);\n        }\n    }\n\n    /**\n     * @notice Calculates sqrt(a), following the selected rounding direction.\n     */\n    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {\n        unchecked {\n            uint256 result = sqrt(a);\n            return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);\n        }\n    }\n\n    /**\n     * @dev Return the log in base 2, rounded down, of a positive value.\n     * Returns 0 if given 0.\n     */\n    function log2(uint256 value) internal pure returns (uint256) {\n        uint256 result = 0;\n        unchecked {\n            if (value >> 128 > 0) {\n                value >>= 128;\n                result += 128;\n            }\n            if (value >> 64 > 0) {\n                value >>= 64;\n                result += 64;\n            }\n            if (value >> 32 > 0) {\n                value >>= 32;\n                result += 32;\n            }\n            if (value >> 16 > 0) {\n                value >>= 16;\n                result += 16;\n            }\n            if (value >> 8 > 0) {\n                value >>= 8;\n                result += 8;\n            }\n            if (value >> 4 > 0) {\n                value >>= 4;\n                result += 4;\n            }\n            if (value >> 2 > 0) {\n                value >>= 2;\n                result += 2;\n            }\n            if (value >> 1 > 0) {\n                result += 1;\n            }\n        }\n        return result;\n    }\n\n    /**\n     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.\n     * Returns 0 if given 0.\n     */\n    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {\n        unchecked {\n            uint256 result = log2(value);\n            return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);\n        }\n    }\n\n    /**\n     * @dev Return the log in base 10, rounded down, of a positive value.\n     * Returns 0 if given 0.\n     */\n    function log10(uint256 value) internal pure returns (uint256) {\n        uint256 result = 0;\n        unchecked {\n            if (value >= 10 ** 64) {\n                value /= 10 ** 64;\n                result += 64;\n            }\n            if (value >= 10 ** 32) {\n                value /= 10 ** 32;\n                result += 32;\n            }\n            if (value >= 10 ** 16) {\n                value /= 10 ** 16;\n                result += 16;\n            }\n            if (value >= 10 ** 8) {\n                value /= 10 ** 8;\n                result += 8;\n            }\n            if (value >= 10 ** 4) {\n                value /= 10 ** 4;\n                result += 4;\n            }\n            if (value >= 10 ** 2) {\n                value /= 10 ** 2;\n                result += 2;\n            }\n            if (value >= 10 ** 1) {\n                result += 1;\n            }\n        }\n        return result;\n    }\n\n    /**\n     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\n     * Returns 0 if given 0.\n     */\n    function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {\n        unchecked {\n            uint256 result = log10(value);\n            return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);\n        }\n    }\n\n    /**\n     * @dev Return the log in base 256, rounded down, of a positive value.\n     * Returns 0 if given 0.\n     *\n     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.\n     */\n    function log256(uint256 value) internal pure returns (uint256) {\n        uint256 result = 0;\n        unchecked {\n            if (value >> 128 > 0) {\n                value >>= 128;\n                result += 16;\n            }\n            if (value >> 64 > 0) {\n                value >>= 64;\n                result += 8;\n            }\n            if (value >> 32 > 0) {\n                value >>= 32;\n                result += 4;\n            }\n            if (value >> 16 > 0) {\n                value >>= 16;\n                result += 2;\n            }\n            if (value >> 8 > 0) {\n                result += 1;\n            }\n        }\n        return result;\n    }\n\n    /**\n     * @dev Return the log in base 256, following the selected rounding direction, of a positive value.\n     * Returns 0 if given 0.\n     */\n    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {\n        unchecked {\n            uint256 result = log256(value);\n            return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);\n        }\n    }\n}\n"
      }
    },
    "settings": {
      "remappings": [],
      "optimizer": {
        "enabled": true,
        "runs": 1
      },
      "evmVersion": "shanghai",
      "libraries": {},
      "outputSelection": {
        "*": {
          "*": [
            "evm.bytecode",
            "evm.deployedBytecode",
            "devdoc",
            "userdoc",
            "metadata",
            "abi"
          ]
        }
      }
    }
  }}