creation_sourcecode: {{
    "language": "Solidity",
    "sources": {
      "contracts/PowerFarms/PendlePowerFarmController/PendlePowerFarmTokenFactory.sol": {
        "content": "// SPDX-License-Identifier: -- WISE --\n\npragma solidity =0.8.25;\n\nimport \"./PendlePowerFarmToken.sol\";\n\nerror DeployForbidden();\n\ncontract PendlePowerFarmTokenFactory {\n\n    address internal constant ZERO_ADDRESS = address(0x0);\n\n    address public immutable IMPLEMENTATION_TARGET;\n    address public immutable PENDLE_POWER_FARM_CONTROLLER;\n\n    constructor(\n        address _pendlePowerFarmController\n    )\n    {\n        PENDLE_POWER_FARM_CONTROLLER = _pendlePowerFarmController;\n\n        PendlePowerFarmToken implementation = new PendlePowerFarmToken{\n            salt: keccak256(\n                abi.encodePacked(\n                    _pendlePowerFarmController\n                )\n            )\n        }();\n\n        IMPLEMENTATION_TARGET = address(\n            implementation\n        );\n    }\n\n    function deploy(\n        address _underlyingPendleMarket,\n        string memory _tokenName,\n        string memory _symbolName,\n        uint16 _maxCardinality\n    )\n        external\n        returns (address)\n    {\n        if (msg.sender != PENDLE_POWER_FARM_CONTROLLER) {\n            revert DeployForbidden();\n        }\n\n        return _clone(\n            _underlyingPendleMarket,\n            _tokenName,\n            _symbolName,\n            _maxCardinality\n        );\n    }\n\n    function _clone(\n        address _underlyingPendleMarket,\n        string memory _tokenName,\n        string memory _symbolName,\n        uint16 _maxCardinality\n    )\n        private\n        returns (address pendlePowerFarmTokenAddress)\n    {\n        bytes32 salt = keccak256(\n            abi.encodePacked(\n                _underlyingPendleMarket\n            )\n        );\n\n        bytes20 targetBytes = bytes20(\n            IMPLEMENTATION_TARGET\n        );\n\n        assembly {\n\n            let clone := mload(0x40)\n\n            mstore(\n                clone,\n                0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000\n            )\n\n            mstore(\n                add(clone, 0x14),\n                targetBytes\n            )\n\n            mstore(\n                add(clone, 0x28),\n                0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000\n            )\n\n            pendlePowerFarmTokenAddress := create2(\n                0,\n                clone,\n                0x37,\n                salt\n            )\n        }\n\n        PendlePowerFarmToken(pendlePowerFarmTokenAddress).initialize(\n            _underlyingPendleMarket,\n            PENDLE_POWER_FARM_CONTROLLER,\n            _tokenName,\n            _symbolName,\n            _maxCardinality\n        );\n    }\n}\n"
      },
      "contracts/PowerFarms/PendlePowerFarmController/PendlePowerFarmToken.sol": {
        "content": "// SPDX-License-Identifier: -- WISE --\n\npragma solidity =0.8.25;\n\nimport \"./SimpleERC20Clone.sol\";\n\nimport \"../../InterfaceHub/IPendle.sol\";\nimport \"../../InterfaceHub/IPendleController.sol\";\n\nimport \"../../TransferHub/TransferHelper.sol\";\n\nerror MarketExpired();\nerror NotController();\nerror ZeroFee();\nerror TooMuchFee();\nerror NotEnoughLpAssetsTransferred();\nerror InsufficientShares();\nerror ZeroAmount();\nerror FeeTooHigh();\nerror NotEnoughShares();\nerror InvalidSharePriceGrowth();\nerror InvalidSharePrice();\nerror AlreadyInitialized();\nerror compoundRoleNotApproved();\nerror AmountBelowMinDeposit();\n\ncontract PendlePowerFarmToken is SimpleERC20, TransferHelper {\n\n    // Pendle - LP token address\n    address public UNDERLYING_PENDLE_MARKET;\n    address public PENDLE_POWER_FARM_CONTROLLER;\n\n    // Total balance of LPs backing at current compound distribution\n    uint256 public underlyingLpAssetsCurrent;\n\n    // Lp assets from compound left to distribute\n    uint256 public totalLpAssetsToDistribute;\n\n    // Interface Object for underlying Market\n    IPendleMarket public PENDLE_MARKET;\n\n    // InterfaceObject for pendle Sy\n    IPendleSy public PENDLE_SY;\n\n    // Interface for Pendle Controller\n    IPendleController public PENDLE_CONTROLLER;\n\n    // Max cardinality of Pendle Market\n    uint16 public MAX_CARDINALITY;\n\n    uint256 public mintFee;\n    uint256 public lastInteraction;\n\n    uint256 private constant ONE_WEEK = 7 days;\n    uint256 internal constant ONE_YEAR = 365 days;\n    uint256 private constant MAX_MINT_FEE = 10000;\n\n    uint256 private constant PRECISION_FACTOR_E6 = 1E6;\n    uint256 private constant PRECISION_FACTOR_E18 = 1E18;\n    uint256 internal constant PRECISION_FACTOR_E36 = PRECISION_FACTOR_E18 * PRECISION_FACTOR_E18;\n    uint256 internal constant PRECISION_FACTOR_YEAR = PRECISION_FACTOR_E18 * ONE_YEAR;\n\n    uint256 MIN_DEPOSIT_AMOUNT = 1E6;\n\n    uint256 private INITIAL_TIME_STAMP;\n\n    uint256 internal constant RESTRICTION_FACTOR = 10\n        * PRECISION_FACTOR_E36\n        / PRECISION_FACTOR_YEAR;\n\n    mapping (address => bool) public compoundRole;\n\n    modifier onlyController() {\n        _onlyController();\n        _;\n    }\n\n    function _onlyController()\n        private\n        view\n    {\n        if (msg.sender != PENDLE_POWER_FARM_CONTROLLER) {\n            revert NotController();\n        }\n    }\n\n    modifier syncSupply()\n    {\n        _triggerIndexUpdate();\n        _overWriteCheck();\n        _syncSupply();\n        _updateRewards();\n        _setLastInteraction();\n        _increaseCardinalityNext();\n        uint256 sharePriceBefore = _getSharePrice();\n        _;\n        _validateSharePriceGrowth(\n            _validateSharePrice(\n                sharePriceBefore\n            )\n        );\n    }\n\n    modifier onlyCompoundRole()\n    {\n        _onlyCompoundRole();\n        _;\n    }\n\n    function _onlyCompoundRole()\n        private\n        view\n    {\n        if (compoundRole[msg.sender] == false) {\n            revert compoundRoleNotApproved();\n        }\n    }\n\n    function _validateSharePrice(\n        uint256 _sharePriceBefore\n    )\n        private\n        view\n        returns (uint256)\n    {\n        uint256 sharePricenNow = _getSharePrice();\n\n        if (sharePricenNow < _sharePriceBefore) {\n            revert InvalidSharePrice();\n        }\n\n        return sharePricenNow;\n    }\n\n    function _validateSharePriceGrowth(\n        uint256 _sharePriceNow\n    )\n        private\n        view\n    {\n        uint256 timeDifference = block.timestamp\n            - INITIAL_TIME_STAMP;\n\n        uint256 maximum = timeDifference\n            * RESTRICTION_FACTOR\n            + PRECISION_FACTOR_E18;\n\n        if (_sharePriceNow > maximum) {\n            revert InvalidSharePriceGrowth();\n        }\n    }\n\n    function _overWriteCheck()\n        internal\n    {\n        _wrapOverWrites(\n            _updateRewardTokens()\n        );\n    }\n\n    function _triggerIndexUpdate()\n        internal\n    {\n        _withdrawLp(\n            UNDERLYING_PENDLE_MARKET,\n            0\n        );\n    }\n\n    function _wrapOverWrites(\n        bool _overWritten\n    )\n        internal\n    {\n        if (_overWritten == true) {\n            _overWriteIndexAll();\n            _overWriteAmounts();\n        }\n    }\n\n    function _updateRewardTokens()\n        private\n        returns (bool)\n    {\n        return PENDLE_CONTROLLER.updateRewardTokens(\n            UNDERLYING_PENDLE_MARKET\n        );\n    }\n\n    function _overWriteIndexAll()\n        private\n    {\n        PENDLE_CONTROLLER.overWriteIndexAll(\n            UNDERLYING_PENDLE_MARKET\n        );\n    }\n\n    function _overWriteIndex(\n        uint256 _index\n    )\n        private\n    {\n        PENDLE_CONTROLLER.overWriteIndex(\n            UNDERLYING_PENDLE_MARKET,\n            _index\n        );\n    }\n\n    function _overWriteAmounts()\n        private\n    {\n        PENDLE_CONTROLLER.overWriteAmounts(\n            UNDERLYING_PENDLE_MARKET\n        );\n    }\n\n    function _updateRewards()\n        private\n    {\n        uint256[] memory rewardsOutsideArray = _calculateRewardsClaimedOutside();\n\n        uint256 i;\n        uint256 l = rewardsOutsideArray.length;\n\n        while (i < l) {\n            if (rewardsOutsideArray[i] > 0) {\n                PENDLE_CONTROLLER.increaseReservedForCompound(\n                    UNDERLYING_PENDLE_MARKET,\n                    rewardsOutsideArray\n                );\n                break;\n            }\n            unchecked {\n                ++i;\n            }\n        }\n    }\n\n    function _calculateRewardsClaimedOutside()\n        internal\n        returns (uint256[] memory)\n    {\n        IPendleController PENDLE_CONTROLLER_INSTANCE = PENDLE_CONTROLLER;\n        address UNDERLYING_PENDLE_MARKET_ADDRESS = UNDERLYING_PENDLE_MARKET;\n\n        address[] memory rewardTokens = PENDLE_CONTROLLER_INSTANCE.pendleChildCompoundInfoRewardTokens(\n            UNDERLYING_PENDLE_MARKET_ADDRESS\n        );\n\n        uint128[] memory lastIndex = PENDLE_CONTROLLER_INSTANCE.pendleChildCompoundInfoLastIndex(\n            UNDERLYING_PENDLE_MARKET_ADDRESS\n        );\n\n        uint256 l = rewardTokens.length;\n        uint256[] memory rewardsOutsideArray = new uint256[](l);\n\n        uint256 i;\n        uint128 index;\n\n        uint256 activeBalance = _getActiveBalance();\n        uint256 totalLpAssetsCurrent = totalLpAssets();\n        uint256 lpBalanceController = _getBalanceLpBalanceController();\n\n        address PENDLE_POWER_FARM_CONTROLLER_ADDRESS = PENDLE_POWER_FARM_CONTROLLER;\n        IPendleMarket PENDLE_MARKET_INSTANCE = PENDLE_MARKET;\n\n        while (i < l) {\n            UserReward memory userReward = _getUserReward(\n                rewardTokens[i],\n                PENDLE_POWER_FARM_CONTROLLER_ADDRESS\n            );\n\n            if (userReward.accrued > 0) {\n                PENDLE_MARKET_INSTANCE.redeemRewards(\n                    PENDLE_POWER_FARM_CONTROLLER_ADDRESS\n                );\n\n                userReward = _getUserReward(\n                    rewardTokens[i],\n                    PENDLE_POWER_FARM_CONTROLLER_ADDRESS\n                );\n            }\n\n            index = userReward.index;\n\n            if (lastIndex[i] == 0 && index > 0) {\n                rewardsOutsideArray[i] = 0;\n                _overWriteIndex(\n                    i\n                );\n                unchecked {\n                    ++i;\n                }\n                continue;\n            }\n\n            if (index == lastIndex[i]) {\n                rewardsOutsideArray[i] = 0;\n                unchecked {\n                    ++i;\n                }\n                continue;\n            }\n\n            uint256 indexDiff = index\n                - lastIndex[i];\n\n            bool scaleNecessary = totalLpAssetsCurrent < lpBalanceController;\n\n            rewardsOutsideArray[i] = scaleNecessary\n                ? indexDiff\n                    * activeBalance\n                    * totalLpAssetsCurrent\n                    / lpBalanceController\n                    / PRECISION_FACTOR_E18\n                : indexDiff\n                    * activeBalance\n                    / PRECISION_FACTOR_E18;\n\n            _overWriteIndex(\n                i\n            );\n\n            unchecked {\n                ++i;\n            }\n        }\n\n        return rewardsOutsideArray;\n    }\n\n    function _getBalanceLpBalanceController()\n        private\n        view\n        returns (uint256)\n    {\n        return PENDLE_MARKET.balanceOf(\n            PENDLE_POWER_FARM_CONTROLLER\n        );\n    }\n\n    function _getActiveBalance()\n        private\n        view\n        returns (uint256)\n    {\n        return PENDLE_MARKET.activeBalance(\n            PENDLE_POWER_FARM_CONTROLLER\n        );\n    }\n\n    function _getSharePrice()\n        private\n        view\n        returns (uint256)\n    {\n        return previewUnderlyingLpAssets() * PRECISION_FACTOR_E18\n            / totalSupply();\n    }\n\n    function _syncSupply()\n        private\n    {\n        uint256 additonalAssets = previewDistribution();\n\n        if (additonalAssets == 0) {\n            return;\n        }\n\n        underlyingLpAssetsCurrent += additonalAssets;\n        totalLpAssetsToDistribute -= additonalAssets;\n    }\n\n    function _increaseCardinalityNext()\n        internal\n    {\n        MarketStorage memory storageMarket = PENDLE_MARKET._storage();\n\n        if (storageMarket.observationCardinalityNext < MAX_CARDINALITY) {\n            PENDLE_MARKET.increaseObservationsCardinalityNext(\n                storageMarket.observationCardinalityNext + 1\n            );\n        }\n    }\n\n    function _withdrawLp(\n        address _to,\n        uint256 _amount\n    )\n        internal\n    {\n        PENDLE_CONTROLLER.withdrawLp(\n            UNDERLYING_PENDLE_MARKET,\n            _to,\n            _amount\n        );\n    }\n\n    function _getUserReward(\n        address _rewardToken,\n        address _user\n    )\n        internal\n        view\n        returns (UserReward memory)\n    {\n        return PENDLE_MARKET.userReward(\n            _rewardToken,\n            _user\n        );\n    }\n\n    function previewDistribution()\n        public\n        view\n        returns (uint256)\n    {\n        uint256 lastInteractioCached = lastInteraction;\n\n        if (totalLpAssetsToDistribute == 0) {\n            return 0;\n        }\n\n        if (block.timestamp == lastInteractioCached) {\n            return 0;\n        }\n\n        if (totalLpAssetsToDistribute < ONE_WEEK) {\n            return totalLpAssetsToDistribute;\n        }\n\n        uint256 currentRate = totalLpAssetsToDistribute\n            / ONE_WEEK;\n\n        uint256 additonalAssets = currentRate\n            * (block.timestamp - lastInteractioCached);\n\n        if (additonalAssets > totalLpAssetsToDistribute) {\n            return totalLpAssetsToDistribute;\n        }\n\n        return additonalAssets;\n    }\n\n    function _setLastInteraction()\n        private\n    {\n        lastInteraction = block.timestamp;\n    }\n\n    function _applyMintFee(\n        uint256 _amount\n    )\n        internal\n        view\n        returns (uint256)\n    {\n        return _amount\n            * (PRECISION_FACTOR_E6 - mintFee)\n            / PRECISION_FACTOR_E6;\n    }\n\n    function totalLpAssets()\n        public\n        view\n        returns (uint256)\n    {\n        return underlyingLpAssetsCurrent\n            + totalLpAssetsToDistribute;\n    }\n\n    function previewUnderlyingLpAssets()\n        public\n        view\n        returns (uint256)\n    {\n        return previewDistribution()\n            + underlyingLpAssetsCurrent;\n    }\n\n    function previewMintShares(\n        uint256 _underlyingAssetAmount,\n        uint256 _underlyingLpAssetsCurrent\n    )\n        public\n        view\n        returns (uint256)\n    {\n        return _underlyingAssetAmount\n            * totalSupply()\n            / _underlyingLpAssetsCurrent;\n    }\n\n    function previewAmountWithdrawShares(\n        uint256 _shares,\n        uint256 _underlyingLpAssetsCurrent\n    )\n        public\n        view\n        returns (uint256)\n    {\n        return _shares\n            * _underlyingLpAssetsCurrent\n            / totalSupply();\n    }\n\n    function previewBurnShares(\n        uint256 _underlyingAssetAmount,\n        uint256 _underlyingLpAssetsCurrent\n    )\n        public\n        view\n        returns (uint256)\n    {\n        uint256 product = _underlyingAssetAmount\n            * totalSupply();\n\n        return product % _underlyingLpAssetsCurrent == 0\n            ? product / _underlyingLpAssetsCurrent\n            : product / _underlyingLpAssetsCurrent + 1;\n    }\n\n    function changeCompoundRoleState(\n        address _compoundRole,\n        bool _state\n    )\n        external\n        onlyController\n    {\n        compoundRole[_compoundRole] = _state;\n    }\n\n    function changeMinDepositAmount(\n        uint256 _newMinDepositAmount\n    )\n        external\n        onlyController\n    {\n        MIN_DEPOSIT_AMOUNT = _newMinDepositAmount;\n    }\n\n    function manualSync()\n        external\n        syncSupply\n        returns (bool)\n    {\n        return true;\n    }\n\n    function addCompoundRewards(\n        uint256 _amount\n    )\n        external\n        syncSupply\n        onlyCompoundRole\n    {\n        if (_amount == 0) {\n            revert ZeroAmount();\n        }\n\n        totalLpAssetsToDistribute += _amount;\n\n        if (msg.sender == PENDLE_POWER_FARM_CONTROLLER) {\n            return;\n        }\n\n        _safeTransferFrom(\n            UNDERLYING_PENDLE_MARKET,\n            msg.sender,\n            PENDLE_POWER_FARM_CONTROLLER,\n            _amount\n        );\n    }\n\n    /**\n     * @dev External wrapper for mint function.\n     */\n    function depositExactAmount(\n        uint256 _underlyingLpAssetAmount\n    )\n        external\n        syncSupply\n        returns (\n            uint256,\n            uint256\n        )\n    {\n        if (_underlyingLpAssetAmount < MIN_DEPOSIT_AMOUNT) {\n            revert AmountBelowMinDeposit();\n        }\n\n        uint256 shares = previewMintShares(\n            _underlyingLpAssetAmount,\n            underlyingLpAssetsCurrent\n        );\n\n        if (shares == 0) {\n            revert NotEnoughLpAssetsTransferred();\n        }\n\n        uint256 reducedShares = _applyMintFee(\n            shares\n        );\n\n        uint256 feeShares = shares\n            - reducedShares;\n\n        if (feeShares == 0) {\n            revert ZeroFee();\n        }\n\n        if (reducedShares == feeShares) {\n            revert TooMuchFee();\n        }\n\n        _mint(\n            msg.sender,\n            reducedShares\n        );\n\n        _mint(\n            PENDLE_POWER_FARM_CONTROLLER,\n            feeShares\n        );\n\n        underlyingLpAssetsCurrent += _underlyingLpAssetAmount;\n\n        _safeTransferFrom(\n            UNDERLYING_PENDLE_MARKET,\n            msg.sender,\n            PENDLE_POWER_FARM_CONTROLLER,\n            _underlyingLpAssetAmount\n        );\n\n        return (\n            reducedShares,\n            feeShares\n        );\n    }\n\n    function changeMintFee(\n        uint256 _newFee\n    )\n        external\n        onlyController\n    {\n        if (_newFee > MAX_MINT_FEE) {\n            revert FeeTooHigh();\n        }\n\n        mintFee = _newFee;\n    }\n\n    /**\n     * @dev External wrapper for burn function.\n     */\n    function withdrawExactShares(\n        uint256 _shares\n    )\n        external\n        syncSupply\n        returns (uint256)\n    {\n        if (_shares == 0) {\n            revert ZeroAmount();\n        }\n\n        if (_shares > balanceOf(msg.sender)) {\n            revert InsufficientShares();\n        }\n\n        uint256 tokenAmount = previewAmountWithdrawShares(\n            _shares,\n            underlyingLpAssetsCurrent\n        );\n\n        underlyingLpAssetsCurrent -= tokenAmount;\n\n        _burn(\n            msg.sender,\n            _shares\n        );\n\n        if (msg.sender == PENDLE_POWER_FARM_CONTROLLER) {\n            return tokenAmount;\n        }\n\n        _withdrawLp(\n            msg.sender,\n            tokenAmount\n        );\n\n        return tokenAmount;\n    }\n\n    function withdrawExactAmount(\n        uint256 _underlyingLpAssetAmount\n    )\n        external\n        syncSupply\n        returns (uint256)\n    {\n        if (_underlyingLpAssetAmount == 0) {\n            revert ZeroAmount();\n        }\n\n        uint256 shares = previewBurnShares(\n            _underlyingLpAssetAmount,\n            underlyingLpAssetsCurrent\n        );\n\n        if (shares > balanceOf(msg.sender)) {\n            revert NotEnoughShares();\n        }\n\n        _burn(\n            msg.sender,\n            shares\n        );\n\n        underlyingLpAssetsCurrent -= _underlyingLpAssetAmount;\n\n        _withdrawLp(\n            msg.sender,\n            _underlyingLpAssetAmount\n        );\n\n        return shares;\n    }\n\n    function initialize(\n        address _underlyingPendleMarket,\n        address _pendleController,\n        string memory _tokenName,\n        string memory _symbolName,\n        uint16 _maxCardinality\n    )\n        external\n    {\n        if (address(PENDLE_MARKET) != address(0)) {\n            revert AlreadyInitialized();\n        }\n\n        PENDLE_MARKET = IPendleMarket(\n            _underlyingPendleMarket\n        );\n\n        if (PENDLE_MARKET.isExpired() == true) {\n            revert MarketExpired();\n        }\n\n        PENDLE_CONTROLLER = IPendleController(\n            _pendleController\n        );\n\n        MAX_CARDINALITY = _maxCardinality;\n\n        _name = _tokenName;\n        _symbol = _symbolName;\n\n        PENDLE_POWER_FARM_CONTROLLER = _pendleController;\n        UNDERLYING_PENDLE_MARKET = _underlyingPendleMarket;\n\n        (\n            address pendleSyAddress,\n            ,\n        ) = PENDLE_MARKET.readTokens();\n\n        PENDLE_SY = IPendleSy(\n            pendleSyAddress\n        );\n\n        _decimals = PENDLE_SY.decimals();\n\n        lastInteraction = block.timestamp;\n\n        _totalSupply = 1;\n        underlyingLpAssetsCurrent = 1;\n        mintFee = 3000;\n        INITIAL_TIME_STAMP = block.timestamp;\n    }\n}\n"
      },
      "contracts/PowerFarms/PendlePowerFarmController/SimpleERC20Clone.sol": {
        "content": "// SPDX-License-Identifier: -- WISE --\n\npragma solidity =0.8.25;\n\nerror AllowanceBelowZero();\nerror ApproveWithZeroAddress();\nerror BurnExceedsBalance();\nerror BurnFromZeroAddress();\nerror InsufficientAllowance();\nerror MintToZeroAddress();\nerror TransferAmountExceedsBalance();\nerror TransferZeroAddress();\n\ncontract SimpleERC20 {\n\n    string internal _name;\n    string internal _symbol;\n\n    uint8 internal _decimals;\n    uint256 internal _totalSupply;\n\n    mapping(address => uint256) internal _balances;\n    mapping(address => mapping(address => uint256)) internal _allowances;\n\n    // Miscellaneous constants\n    uint256 internal constant UINT256_MAX = type(uint256).max;\n    address internal constant ZERO_ADDRESS = address(0);\n\n    event Transfer(\n        address indexed from,\n        address indexed to,\n        uint256 value\n    );\n\n    event Approval(\n        address indexed owner,\n        address indexed spender,\n        uint256 value\n    );\n\n    function name()\n        external\n        view\n        returns (string memory)\n    {\n        return _name;\n    }\n\n    function symbol()\n        external\n        view\n        returns (string memory)\n    {\n        return _symbol;\n    }\n\n    function decimals()\n        external\n        view\n        returns (uint8)\n    {\n        return _decimals;\n    }\n\n    function totalSupply()\n        public\n        view\n        returns (uint256)\n    {\n        return _totalSupply;\n    }\n\n    function balanceOf(\n        address _account\n    )\n        public\n        view\n        returns (uint256)\n    {\n        return _balances[_account];\n    }\n\n    function _transfer(\n        address _from,\n        address _to,\n        uint256 _amount\n    )\n        internal\n    {\n        if (_from == ZERO_ADDRESS || _to == ZERO_ADDRESS) {\n            revert TransferZeroAddress();\n        }\n\n        uint256 fromBalance = _balances[_from];\n\n        if (fromBalance < _amount) {\n            revert TransferAmountExceedsBalance();\n        }\n\n        unchecked {\n            _balances[_from] = fromBalance - _amount;\n            _balances[_to] += _amount;\n        }\n\n        emit Transfer(\n            _from,\n            _to,\n            _amount\n        );\n    }\n\n    function _mint(\n        address _account,\n        uint256 _amount\n    )\n        internal\n    {\n        if (_account == ZERO_ADDRESS) {\n            revert MintToZeroAddress();\n        }\n\n        _totalSupply += _amount;\n\n        unchecked {\n            _balances[_account] += _amount;\n        }\n\n        emit Transfer(\n            ZERO_ADDRESS,\n            _account,\n            _amount\n        );\n    }\n\n    function _burn(\n        address _account,\n        uint256 _amount\n    )\n        internal\n    {\n        if (_account == ZERO_ADDRESS) {\n            revert BurnFromZeroAddress();\n        }\n\n        uint256 accountBalance = _balances[\n            _account\n        ];\n\n        if (accountBalance < _amount) {\n            revert BurnExceedsBalance();\n        }\n\n        unchecked {\n            _balances[_account] = accountBalance - _amount;\n            _totalSupply -= _amount;\n        }\n\n        emit Transfer(\n            _account,\n            ZERO_ADDRESS,\n            _amount\n        );\n    }\n\n    function transfer(\n        address _to,\n        uint256 _amount\n    )\n        external\n        returns (bool)\n    {\n        _transfer(\n            _msgSender(),\n            _to,\n            _amount\n        );\n\n        return true;\n    }\n\n    function allowance(\n        address _owner,\n        address _spender\n    )\n        public\n        view\n        returns (uint256)\n    {\n        return _allowances[_owner][_spender];\n    }\n\n    function approve(\n        address _spender,\n        uint256 _amount\n    )\n        external\n        returns (bool)\n    {\n        _approve(\n            _msgSender(),\n            _spender,\n            _amount\n        );\n\n        return true;\n    }\n\n    function transferFrom(\n        address _from,\n        address _to,\n        uint256 _amount\n    )\n        external\n        returns (bool)\n    {\n        _spendAllowance(\n            _from,\n            _msgSender(),\n            _amount\n        );\n\n        _transfer(\n            _from,\n            _to,\n            _amount\n        );\n\n        return true;\n    }\n\n    function increaseAllowance(\n        address _spender,\n        uint256 _addedValue\n    )\n        external\n        returns (bool)\n    {\n        address owner = _msgSender();\n\n        _approve(\n            owner,\n            _spender,\n            allowance(owner, _spender) + _addedValue\n        );\n\n        return true;\n    }\n\n    function decreaseAllowance(\n        address _spender,\n        uint256 _subtractedValue\n    )\n        external\n        returns (bool)\n    {\n        address owner = _msgSender();\n\n        uint256 currentAllowance = allowance(\n            owner,\n            _spender\n        );\n\n        if (currentAllowance < _subtractedValue) {\n            revert AllowanceBelowZero();\n        }\n\n        unchecked {\n            _approve(\n                owner,\n                _spender,\n                currentAllowance - _subtractedValue\n            );\n        }\n\n        return true;\n    }\n\n    function _approve(\n        address _owner,\n        address _spender,\n        uint256 _amount\n    )\n        internal\n    {\n        if (_owner == ZERO_ADDRESS || _spender == ZERO_ADDRESS) {\n            revert ApproveWithZeroAddress();\n        }\n\n        _allowances[_owner][_spender] = _amount;\n\n        emit Approval(\n            _owner,\n            _spender,\n            _amount\n        );\n    }\n\n    function _spendAllowance(\n        address _owner,\n        address _spender,\n        uint256 _amount\n    )\n        internal\n    {\n        uint256 currentAllowance = allowance(\n            _owner,\n            _spender\n        );\n\n        if (currentAllowance != UINT256_MAX) {\n\n            if (currentAllowance < _amount) {\n                revert InsufficientAllowance();\n            }\n\n            unchecked {\n                _approve(\n                    _owner,\n                    _spender,\n                    currentAllowance - _amount\n                );\n            }\n        }\n    }\n\n    function _msgSender()\n        internal\n        view\n        returns (address)\n    {\n        return msg.sender;\n    }\n}\n"
      },
      "contracts/InterfaceHub/IPendle.sol": {
        "content": "// SPDX-License-Identifier: -- WISE --\n\npragma solidity =0.8.25;\n\nstruct MarketStorage {\n    int128 totalPt;\n    int128 totalSy;\n    uint96 lastLnImpliedRate;\n    uint16 observationIndex;\n    uint16 observationCardinality;\n    uint16 observationCardinalityNext;\n}\n\nstruct MarketState {\n    int256 totalPt;\n    int256 totalSy;\n    int256 totalLp;\n    address treasury;\n    int256 scalarRoot;\n    uint256 expiry;\n    uint256 lnFeeRateRoot;\n    uint256 reserveFeePercent;\n    uint256 lastLnImpliedRate;\n}\n\nstruct LockedPosition {\n    uint128 amount;\n    uint128 expiry;\n}\n\nstruct UserReward {\n    uint128 index;\n    uint128 accrued;\n}\n\nstruct ApproxParams {\n    uint256 guessMin;\n    uint256 guessMax;\n    uint256 guessOffchain;\n    uint256 maxIteration;\n    uint256 eps;\n}\n\ninterface IPendleSy {\n\n    function decimals()\n        external\n        view\n        returns (uint8);\n\n    function previewDeposit(\n        address _tokenIn,\n        uint256 _amountTokenToDeposit\n    )\n        external\n        view\n        returns (uint256 sharesAmount);\n\n    function deposit(\n        address _receiver,\n        address _tokenIn,\n        uint256 _amountTokenToDeposit,\n        uint256 _minSharesOut\n    )\n        external\n        returns (uint256 sharesAmount);\n\n    function exchangeRate()\n        external\n        view\n        returns (uint256);\n\n    function redeem(\n        address _receiver,\n        uint256 _amountSharesToRedeem,\n        address _tokenOut,\n        uint256 _minTokenOut,\n        bool _burnFromInternalBalance\n    )\n        external\n        returns (uint256 amountTokenOut);\n}\n\ninterface IPendleYt {\n\n    function mintPY(\n        address _receiverPT,\n        address _receiverYT\n    )\n        external\n        returns (uint256 pyAmount);\n\n    function redeemPY(\n        address _receiver\n    )\n        external\n        returns (uint256);\n\n    function redeemDueInterestAndRewards(\n        address _user,\n        bool _redeemInterest,\n        bool _redeemRewards\n    )\n        external\n        returns (\n            uint256 interestOut,\n            uint256[] memory rewardsOut\n        );\n\n    function getRewardTokens()\n        external\n        view\n        returns (address[] memory);\n\n    function userReward(\n        address _token,\n        address _user\n    )\n        external\n        view\n        returns (UserReward memory);\n\n    function userInterest(\n        address user\n    )\n        external\n        view\n        returns (\n            uint128 lastPYIndex,\n            uint128 accruedInterest\n        );\n\n    function pyIndexStored()\n        external\n        view\n        returns (uint256);\n}\n\ninterface IPendleMarket {\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    )\n        external;\n\n    function readTokens()\n        external\n        view\n        returns (\n            address SY,\n            address PT,\n            address YT\n        );\n\n    function activeBalance(\n        address _user\n    )\n        external\n        view\n        returns (uint256);\n\n    function transferFrom(\n        address _from,\n        address _to,\n        uint256 _amount\n    )\n        external;\n\n    function balanceOf(\n        address _user\n    )\n        external\n        view\n        returns (uint256);\n\n    function isExpired()\n        external\n        view\n        returns (bool);\n\n    function decimals()\n        external\n        view\n        returns (uint8);\n\n    function increaseObservationsCardinalityNext(\n        uint16 _newObservationCardinalityNext\n    )\n        external;\n\n    function swapExactPtForSy(\n        address receiver,\n        uint256 exactPtIn,\n        bytes calldata data\n    )\n        external\n        returns (\n            uint256 netSyOut,\n            uint256 netSyFee\n        );\n\n    function _storage()\n        external\n        view\n        returns (MarketStorage memory);\n\n    function getRewardTokens()\n        external\n        view\n        returns (address[] memory);\n\n    function readState(\n        address _router\n    )\n        external\n        view\n        returns (MarketState memory marketState);\n\n    function mint(\n        address _receiver,\n        uint256 _netSyDesired,\n        uint256 _netPtDesired\n    )\n        external\n        returns (uint256[3] memory);\n\n    function burn(\n        address _receiverAddressSy,\n        address _receiverAddressPt,\n        uint256 _lpToBurn\n    )\n        external\n        returns (\n            uint256 syOut,\n            uint256 ptOut\n        );\n\n    function redeemRewards(\n        address _user\n    )\n        external\n        returns (uint256[] memory);\n\n    function totalSupply()\n        external\n        view\n        returns (uint256);\n\n    function userReward(\n        address _token,\n        address _user\n    )\n        external\n        view\n        returns (UserReward memory);\n}\n\ninterface IPendleChild {\n\n    function underlyingLpAssetsCurrent()\n        external\n        view\n        returns (uint256);\n\n    function totalLpAssets()\n        external\n        view\n        returns (uint256);\n\n    function totalSupply()\n        external\n        view\n        returns (uint256);\n\n    function previewUnderlyingLpAssets()\n        external\n        view\n        returns (uint256);\n\n    function previewMintShares(\n        uint256 _underlyingAssetAmount,\n        uint256 _underlyingLpAssetsCurrent\n    )\n        external\n        view\n        returns (uint256);\n\n    function previewAmountWithdrawShares(\n        uint256 _shares,\n        uint256 _underlyingLpAssetsCurrent\n    )\n        external\n        view\n        returns (uint256);\n\n    function previewBurnShares(\n        uint256 _underlyingAssetAmount,\n        uint256 _underlyingLpAssetsCurrent\n    )\n        external\n        view\n        returns (uint256);\n\n    function depositExactAmount(\n        uint256 _amount\n    )\n        external\n        returns (\n            uint256,\n            uint256\n        );\n\n    function withdrawExactShares(\n        uint256 _shares\n    )\n        external\n        returns (uint256);\n}\n\ninterface IPendleLock {\n\n    function increaseLockPosition(\n        uint128 _additionalAmountToLock,\n        uint128 _newExpiry\n    )\n        external\n        returns (uint128 newVeBalance);\n\n    function withdraw()\n        external\n        returns (uint128);\n\n    function positionData(\n        address _user\n    )\n        external\n        view\n        returns (LockedPosition memory);\n\n    function getBroadcastPositionFee(\n        uint256[] calldata _chainIds\n    )\n        external\n        view\n        returns (uint256);\n}\n\ninterface IPendleVoteRewards {\n    function claimRetail(\n        address _user,\n        uint256 _amount,\n        bytes32[] calldata _merkleProof\n    )\n        external\n        returns (uint256);\n}\n\ninterface IPendleVoter {\n    function vote(\n        address[] memory _pools,\n        uint64[] memory _weights\n    )\n        external;\n}\n\ninterface IPendleRouter {\n\n    function swapSyForExactYt(\n        address _receiver,\n        address _market,\n        uint256 _exactYtOut,\n        uint256 _maxSyIn\n    )\n        external\n        returns (\n            uint256 netSyIn,\n            uint256 netSyFee\n        );\n\n    function swapExactSyForYt(\n        address _receiver,\n        address _market,\n        uint256 _exactSyIn,\n        uint256 _minYtOut\n    )\n        external\n        returns (\n            uint256 netYtOut,\n            uint256 netSyFee\n        );\n\n    function swapSyForExactPt(\n        address _receiver,\n        address _market,\n        uint256 _exactPtOut,\n        uint256 _maxSyIn\n    )\n        external\n        returns (\n            uint256 netSyIn,\n            uint256 netSyFee\n        );\n\n    function swapExactSyForPt(\n        address _receiver,\n        address _market,\n        uint256 _exactSyIn,\n        uint256 _minPtOut\n    )\n        external\n        returns (\n            uint256 netPtOut,\n            uint256 netSyFee\n        );\n\n    function removeLiquiditySingleSy(\n        address _receiver,\n        address _market,\n        uint256 _netLpToRemove,\n        uint256 _minSyOut\n    )\n        external\n        returns (\n            uint256 netSyOut,\n            uint256 netSyFee\n        );\n\n    function addLiquiditySingleSy(\n        address _receiver,\n        address _market,\n        uint256 _netSyIn,\n        uint256 _minLpOut,\n        ApproxParams calldata _guessPtReceivedFromSy\n    )\n        external\n        returns (\n            uint256 netLpOut,\n            uint256 netSyFee\n        );\n}\n\ninterface IPendleRouterStatic {\n\n    function addLiquiditySingleSyStatic(\n        address _market,\n        uint256 _netSyIn\n    )\n        external\n        view\n        returns (\n            uint256 netLpOut,\n            uint256 netPtFromSwap,\n            uint256 netSyFee,\n            uint256 priceImpact,\n            uint256 exchangeRateAfter,\n            uint256 netSyToSwap\n        );\n\n    function swapExactPtForSyStatic(\n        address _market,\n        uint256 _exactPtIn\n    )\n        external\n        view\n        returns (\n            uint256 netSyOut,\n            uint256 netSyFee,\n            uint256 priceImpact,\n            uint256 exchangeRateAfter\n        );\n}\n"
      },
      "contracts/InterfaceHub/IPendleController.sol": {
        "content": "// SPDX-License-Identifier: -- WISE --\n\npragma solidity =0.8.25;\n\ninterface IPendleController {\n\n    struct compoundStruct {\n        uint256[] reservedForCompound;\n        uint128[] lastIndex;\n        address[] rewardTokens;\n    }\n\n    function withdrawLp(\n        address _pendleMarket,\n        address _to,\n        uint256 _amount\n    )\n        external;\n\n    function increaseReservedForCompound(\n        address _pendleMarket,\n        uint256[] memory _amounts\n    )\n        external;\n\n    function pendleChildCompoundInfoReservedForCompound(\n        address _pendleMarket\n    )\n        external\n        view\n        returns (uint256[] memory);\n\n    function pendleChildCompoundInfoLastIndex(\n        address _pendleMarket\n    )\n        external\n        view\n        returns (uint128[] memory);\n\n    function pendleChildCompoundInfoRewardTokens(\n        address _pendleMarket\n    )\n        external\n        view\n        returns (address[] memory);\n\n    function updateRewardTokens(\n        address _pendleMarket\n    )\n        external\n        returns (bool);\n\n    function overWriteIndexAll(\n        address _pendleMarket\n    )\n        external;\n\n    function overWriteIndex(\n        address _pendleMarket,\n        uint256 _index\n    )\n        external;\n\n    function overWriteAmounts(\n        address _pendleMarket\n    )\n        external;\n}\n"
      },
      "contracts/TransferHub/TransferHelper.sol": {
        "content": "// SPDX-License-Identifier: -- WISE --\n\npragma solidity =0.8.25;\n\nimport \"./CallOptionalReturn.sol\";\n\ncontract TransferHelper is CallOptionalReturn {\n\n    /**\n     * @dev\n     * Allows to execute safe transfer for a token\n     */\n    function _safeTransfer(\n        address _token,\n        address _to,\n        uint256 _value\n    )\n        internal\n    {\n        _callOptionalReturn(\n            _token,\n            abi.encodeWithSelector(\n                IERC20.transfer.selector,\n                _to,\n                _value\n            )\n        );\n    }\n\n    /**\n     * @dev\n     * Allows to execute safe transferFrom for a token\n     */\n    function _safeTransferFrom(\n        address _token,\n        address _from,\n        address _to,\n        uint256 _value\n    )\n        internal\n    {\n        _callOptionalReturn(\n            _token,\n            abi.encodeWithSelector(\n                IERC20.transferFrom.selector,\n                _from,\n                _to,\n                _value\n            )\n        );\n    }\n}\n"
      },
      "contracts/TransferHub/CallOptionalReturn.sol": {
        "content": "// SPDX-License-Identifier: -- WISE --\n\npragma solidity =0.8.25;\n\nimport \"../InterfaceHub/IERC20.sol\";\n\ncontract CallOptionalReturn {\n\n    /**\n     * @dev Helper function to do low-level call\n     */\n    function _callOptionalReturn(\n        address token,\n        bytes memory data\n    )\n        internal\n        returns (bool call)\n    {\n        (\n            bool success,\n            bytes memory returndata\n        ) = token.call(\n            data\n        );\n\n        bool results = returndata.length == 0 || abi.decode(\n            returndata,\n            (bool)\n        );\n\n        if (success == false) {\n            revert();\n        }\n\n        call = success\n            && results\n            && token.code.length > 0;\n    }\n}"
      },
      "contracts/InterfaceHub/IERC20.sol": {
        "content": "// SPDX-License-Identifier: -- WISE --\n\npragma solidity =0.8.25;\n\ninterface IERC20 {\n\n    function totalSupply()\n        external\n        view\n        returns (uint256);\n\n    function balanceOf(\n        address _account\n    )\n        external\n        view\n        returns (uint256);\n\n    function transferFrom(\n        address _sender,\n        address _recipient,\n        uint256 _amount\n    )\n        external\n        returns (bool);\n\n    function transfer(\n        address _recipient,\n        uint256 _amount\n    )\n        external\n        returns (bool);\n\n    function allowance(\n        address owner,\n        address spender\n    )\n        external\n        view\n        returns (uint256);\n\n    function approve(\n        address _spender,\n        uint256 _amount\n    )\n        external\n        returns (bool);\n\n    function decimals()\n        external\n        view\n        returns (uint8);\n\n    event Transfer(\n        address indexed from,\n        address indexed to,\n        uint256 value\n    );\n\n    event Approval(\n        address indexed owner,\n        address indexed spender,\n        uint256 value\n    );\n\n    event  Deposit(\n        address indexed dst,\n        uint wad\n    );\n\n    event  Withdrawal(\n        address indexed src,\n        uint wad\n    );\n}\n"
      }
    },
    "settings": {
      "remappings": [
        "@balancer-labs/=node_modules/@balancer-labs/",
        "@chainlink/=node_modules/@chainlink/",
        "@ensdomains/=node_modules/@ensdomains/",
        "@eth-optimism/=node_modules/@eth-optimism/",
        "@ethereum-waffle/=node_modules/@ethereum-waffle/",
        "@openzeppelin/=node_modules/@openzeppelin/",
        "@pendle/=node_modules/@pendle/",
        "@uniswap/=node_modules/@uniswap/",
        "base64-sol/=node_modules/base64-sol/",
        "ds-test/=lib/forge-std/lib/ds-test/src/",
        "eth-gas-reporter/=node_modules/eth-gas-reporter/",
        "forge-std/=lib/forge-std/src/",
        "hardhat/=node_modules/hardhat/"
      ],
      "optimizer": {
        "enabled": true,
        "runs": 20
      },
      "metadata": {
        "useLiteralContent": false,
        "bytecodeHash": "ipfs",
        "appendCBOR": true
      },
      "outputSelection": {
        "*": {
          "*": [
            "evm.bytecode",
            "evm.deployedBytecode",
            "devdoc",
            "userdoc",
            "metadata",
            "abi"
          ]
        }
      },
      "evmVersion": "shanghai",
      "viaIR": false,
      "libraries": {}
    }
  }}