{"constructor_args":"0x0000000000000000000000009eaaeda23177b7168c55a3a0f937f6791973344900000000000000000000000000000000000000000000000000000000000003840000000000000000000000000000000000000000000000000000000000000001","is_partially_verified":true,"is_changed_bytecode":false,"abi":[{"inputs":[{"internalType":"address","name":"_market","type":"address"},{"internalType":"uint32","name":"_twapDuration","type":"uint32"},{"internalType":"enum PendleOracleType","name":"_baseOracleType","type":"uint8"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"InvalidRoundId","type":"error"},{"inputs":[{"internalType":"int256","name":"exchangeRate","type":"int256"}],"name":"MarketExchangeRateBelowOne","type":"error"},{"inputs":[],"name":"MarketExpired","type":"error"},{"inputs":[],"name":"MarketProportionMustNotEqualOne","type":"error"},{"inputs":[{"internalType":"int256","name":"rateScalar","type":"int256"}],"name":"MarketRateScalarBelowZero","type":"error"},{"inputs":[{"internalType":"int256","name":"totalPt","type":"int256"},{"internalType":"int256","name":"totalAsset","type":"int256"}],"name":"MarketZeroTotalPtOrTotalAsset","type":"error"},{"inputs":[],"name":"baseOracleType","outputs":[{"internalType":"enum PendleOracleType","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"description","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"fromTokenScale","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint80","name":"roundId","type":"uint80"}],"name":"getRoundData","outputs":[{"internalType":"uint80","name":"","type":"uint80"},{"internalType":"int256","name":"","type":"int256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint80","name":"","type":"uint80"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"latestRoundData","outputs":[{"internalType":"uint80","name":"roundId","type":"uint80"},{"internalType":"int256","name":"answer","type":"int256"},{"internalType":"uint256","name":"startedAt","type":"uint256"},{"internalType":"uint256","name":"updatedAt","type":"uint256"},{"internalType":"uint80","name":"answeredInRound","type":"uint80"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"market","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"toTokenScale","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"twapDuration","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"}],"conflicting_implementations":null,"certified":false,"additional_sources":[{"file_path":"@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol","source_code":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\ninterface AggregatorV3Interface {\n  function decimals() external view returns (uint8);\n\n  function description() external view returns (string memory);\n\n  function version() external view returns (uint256);\n\n  function getRoundData(\n    uint80 _roundId\n  ) external view returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);\n\n  function latestRoundData()\n    external\n    view\n    returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);\n}\n"},{"file_path":"contracts/interfaces/IPPrincipalToken.sol","source_code":"// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity ^0.8.0;\nimport \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\n\ninterface IPPrincipalToken is IERC20Metadata {\n    function burnByYT(address user, uint256 amount) external;\n\n    function mintByYT(address user, uint256 amount) external;\n\n    function initialize(address _YT) external;\n\n    function SY() external view returns (address);\n\n    function YT() external view returns (address);\n\n    function factory() external view returns (address);\n\n    function expiry() external view returns (uint256);\n\n    function isExpired() external view returns (bool);\n}\n"},{"file_path":"contracts/interfaces/IPYieldToken.sol","source_code":"// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity ^0.8.0;\nimport \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\nimport \"./IRewardManager.sol\";\nimport \"./IPInterestManagerYT.sol\";\n\ninterface IPYieldToken is IERC20Metadata, IRewardManager, IPInterestManagerYT {\n    event NewInterestIndex(uint256 indexed newIndex);\n\n    event Mint(\n        address indexed caller,\n        address indexed receiverPT,\n        address indexed receiverYT,\n        uint256 amountSyToMint,\n        uint256 amountPYOut\n    );\n\n    event Burn(address indexed caller, address indexed receiver, uint256 amountPYToRedeem, uint256 amountSyOut);\n\n    event RedeemRewards(address indexed user, uint256[] amountRewardsOut);\n\n    event RedeemInterest(address indexed user, uint256 interestOut);\n\n    event CollectRewardFee(address indexed rewardToken, uint256 amountRewardFee);\n\n    function mintPY(address receiverPT, address receiverYT) external returns (uint256 amountPYOut);\n\n    function redeemPY(address receiver) external returns (uint256 amountSyOut);\n\n    function redeemPYMulti(\n        address[] calldata receivers,\n        uint256[] calldata amountPYToRedeems\n    ) external returns (uint256[] memory amountSyOuts);\n\n    function redeemDueInterestAndRewards(\n        address user,\n        bool redeemInterest,\n        bool redeemRewards\n    ) external returns (uint256 interestOut, uint256[] memory rewardsOut);\n\n    function rewardIndexesCurrent() external returns (uint256[] memory);\n\n    function pyIndexCurrent() external returns (uint256);\n\n    function pyIndexStored() external view returns (uint256);\n\n    function getRewardTokens() external view returns (address[] memory);\n\n    function SY() external view returns (address);\n\n    function PT() external view returns (address);\n\n    function factory() external view returns (address);\n\n    function expiry() external view returns (uint256);\n\n    function isExpired() external view returns (bool);\n\n    function doCacheIndexSameBlock() external view returns (bool);\n\n    function pyIndexLastUpdatedBlock() external view returns (uint128);\n}\n"},{"file_path":"contracts/interfaces/IRewardManager.sol","source_code":"// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity ^0.8.0;\n\ninterface IRewardManager {\n    function userReward(address token, address user) external view returns (uint128 index, uint128 accrued);\n}\n"},{"file_path":"contracts/interfaces/IStandardizedYield.sol","source_code":"// SPDX-License-Identifier: GPL-3.0-or-later\n/*\n * MIT License\n * ===========\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n */\n\npragma solidity ^0.8.0;\nimport \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\n\ninterface IStandardizedYield is IERC20Metadata {\n    /// @dev Emitted when any base tokens is deposited to mint shares\n    event Deposit(\n        address indexed caller,\n        address indexed receiver,\n        address indexed tokenIn,\n        uint256 amountDeposited,\n        uint256 amountSyOut\n    );\n\n    /// @dev Emitted when any shares are redeemed for base tokens\n    event Redeem(\n        address indexed caller,\n        address indexed receiver,\n        address indexed tokenOut,\n        uint256 amountSyToRedeem,\n        uint256 amountTokenOut\n    );\n\n    /// @dev check `assetInfo()` for more information\n    enum AssetType {\n        TOKEN,\n        LIQUIDITY\n    }\n\n    /// @dev Emitted when (`user`) claims their rewards\n    event ClaimRewards(address indexed user, address[] rewardTokens, uint256[] rewardAmounts);\n\n    /**\n     * @notice mints an amount of shares by depositing a base token.\n     * @param receiver shares recipient address\n     * @param tokenIn address of the base tokens to mint shares\n     * @param amountTokenToDeposit amount of base tokens to be transferred from (`msg.sender`)\n     * @param minSharesOut reverts if amount of shares minted is lower than this\n     * @return amountSharesOut amount of shares minted\n     * @dev Emits a {Deposit} event\n     *\n     * Requirements:\n     * - (`tokenIn`) must be a valid base token.\n     */\n    function deposit(\n        address receiver,\n        address tokenIn,\n        uint256 amountTokenToDeposit,\n        uint256 minSharesOut\n    ) external payable returns (uint256 amountSharesOut);\n\n    /**\n     * @notice redeems an amount of base tokens by burning some shares\n     * @param receiver recipient address\n     * @param amountSharesToRedeem amount of shares to be burned\n     * @param tokenOut address of the base token to be redeemed\n     * @param minTokenOut reverts if amount of base token redeemed is lower than this\n     * @param burnFromInternalBalance if true, burns from balance of `address(this)`, otherwise burns from `msg.sender`\n     * @return amountTokenOut amount of base tokens redeemed\n     * @dev Emits a {Redeem} event\n     *\n     * Requirements:\n     * - (`tokenOut`) must be a valid base token.\n     */\n    function redeem(\n        address receiver,\n        uint256 amountSharesToRedeem,\n        address tokenOut,\n        uint256 minTokenOut,\n        bool burnFromInternalBalance\n    ) external returns (uint256 amountTokenOut);\n\n    /**\n     * @notice exchangeRate * syBalance / 1e18 must return the asset balance of the account\n     * @notice vice-versa, if a user uses some amount of tokens equivalent to X asset, the amount of sy\n     he can mint must be X * exchangeRate / 1e18\n     * @dev SYUtils's assetToSy & syToAsset should be used instead of raw multiplication\n     & division\n     */\n    function exchangeRate() external view returns (uint256 res);\n\n    /**\n     * @notice claims reward for (`user`)\n     * @param user the user receiving their rewards\n     * @return rewardAmounts an array of reward amounts in the same order as `getRewardTokens`\n     * @dev\n     * Emits a `ClaimRewards` event\n     * See {getRewardTokens} for list of reward tokens\n     */\n    function claimRewards(address user) external returns (uint256[] memory rewardAmounts);\n\n    /**\n     * @notice get the amount of unclaimed rewards for (`user`)\n     * @param user the user to check for\n     * @return rewardAmounts an array of reward amounts in the same order as `getRewardTokens`\n     */\n    function accruedRewards(address user) external view returns (uint256[] memory rewardAmounts);\n\n    function rewardIndexesCurrent() external returns (uint256[] memory indexes);\n\n    function rewardIndexesStored() external view returns (uint256[] memory indexes);\n\n    /**\n     * @notice returns the list of reward token addresses\n     */\n    function getRewardTokens() external view returns (address[] memory);\n\n    /**\n     * @notice returns the address of the underlying yield token\n     */\n    function yieldToken() external view returns (address);\n\n    /**\n     * @notice returns all tokens that can mint this SY\n     */\n    function getTokensIn() external view returns (address[] memory res);\n\n    /**\n     * @notice returns all tokens that can be redeemed by this SY\n     */\n    function getTokensOut() external view returns (address[] memory res);\n\n    function isValidTokenIn(address token) external view returns (bool);\n\n    function isValidTokenOut(address token) external view returns (bool);\n\n    function previewDeposit(\n        address tokenIn,\n        uint256 amountTokenToDeposit\n    ) external view returns (uint256 amountSharesOut);\n\n    function previewRedeem(\n        address tokenOut,\n        uint256 amountSharesToRedeem\n    ) external view returns (uint256 amountTokenOut);\n\n    /**\n     * @notice This function contains information to interpret what the asset is\n     * @return assetType the type of the asset (0 for ERC20 tokens, 1 for AMM liquidity tokens,\n        2 for bridged yield bearing tokens like wstETH, rETH on Arbi whose the underlying asset doesn't exist on the chain)\n     * @return assetAddress the address of the asset\n     * @return assetDecimals the decimals of the asset\n     */\n    function assetInfo() external view returns (AssetType assetType, address assetAddress, uint8 assetDecimals);\n}\n"},{"file_path":"@openzeppelin/contracts/token/ERC20/IERC20.sol","source_code":"// 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 IERC20 {\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"},{"file_path":"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20.sol\";\n\n/**\n * @dev Interface for the optional metadata functions from the ERC20 standard.\n *\n * _Available since v4.1._\n */\ninterface IERC20Metadata is IERC20 {\n    /**\n     * @dev Returns the name of the token.\n     */\n    function name() external view returns (string memory);\n\n    /**\n     * @dev Returns the symbol of the token.\n     */\n    function symbol() external view returns (string memory);\n\n    /**\n     * @dev Returns the decimals places of the token.\n     */\n    function decimals() external view returns (uint8);\n}\n"},{"file_path":"contracts/core/Market/MarketMathCore.sol","source_code":"// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity ^0.8.0;\n\nimport \"../libraries/math/PMath.sol\";\nimport \"../libraries/math/LogExpMath.sol\";\n\nimport \"../StandardizedYield/PYIndex.sol\";\nimport \"../libraries/MiniHelpers.sol\";\nimport \"../libraries/Errors.sol\";\n\nstruct MarketState {\n    int256 totalPt;\n    int256 totalSy;\n    int256 totalLp;\n    address treasury;\n    /// immutable variables ///\n    int256 scalarRoot;\n    uint256 expiry;\n    /// fee data ///\n    uint256 lnFeeRateRoot;\n    uint256 reserveFeePercent; // base 100\n    /// last trade data ///\n    uint256 lastLnImpliedRate;\n}\n\n// params that are expensive to compute, therefore we pre-compute them\nstruct MarketPreCompute {\n    int256 rateScalar;\n    int256 totalAsset;\n    int256 rateAnchor;\n    int256 feeRate;\n}\n\n// solhint-disable ordering\nlibrary MarketMathCore {\n    using PMath for uint256;\n    using PMath for int256;\n    using LogExpMath for int256;\n    using PYIndexLib for PYIndex;\n\n    int256 internal constant MINIMUM_LIQUIDITY = 10 ** 3;\n    int256 internal constant PERCENTAGE_DECIMALS = 100;\n    uint256 internal constant DAY = 86400;\n    uint256 internal constant IMPLIED_RATE_TIME = 365 * DAY;\n\n    int256 internal constant MAX_MARKET_PROPORTION = (1e18 * 96) / 100;\n\n    using PMath for uint256;\n    using PMath for int256;\n\n    /*///////////////////////////////////////////////////////////////\n                UINT FUNCTIONS TO PROXY TO CORE FUNCTIONS\n    //////////////////////////////////////////////////////////////*/\n\n    function addLiquidity(\n        MarketState memory market,\n        uint256 syDesired,\n        uint256 ptDesired,\n        uint256 blockTime\n    ) internal pure returns (uint256 lpToReserve, uint256 lpToAccount, uint256 syUsed, uint256 ptUsed) {\n        (int256 _lpToReserve, int256 _lpToAccount, int256 _syUsed, int256 _ptUsed) = addLiquidityCore(\n            market,\n            syDesired.Int(),\n            ptDesired.Int(),\n            blockTime\n        );\n\n        lpToReserve = _lpToReserve.Uint();\n        lpToAccount = _lpToAccount.Uint();\n        syUsed = _syUsed.Uint();\n        ptUsed = _ptUsed.Uint();\n    }\n\n    function removeLiquidity(\n        MarketState memory market,\n        uint256 lpToRemove\n    ) internal pure returns (uint256 netSyToAccount, uint256 netPtToAccount) {\n        (int256 _syToAccount, int256 _ptToAccount) = removeLiquidityCore(market, lpToRemove.Int());\n\n        netSyToAccount = _syToAccount.Uint();\n        netPtToAccount = _ptToAccount.Uint();\n    }\n\n    function swapExactPtForSy(\n        MarketState memory market,\n        PYIndex index,\n        uint256 exactPtToMarket,\n        uint256 blockTime\n    ) internal pure returns (uint256 netSyToAccount, uint256 netSyFee, uint256 netSyToReserve) {\n        (int256 _netSyToAccount, int256 _netSyFee, int256 _netSyToReserve) = executeTradeCore(\n            market,\n            index,\n            exactPtToMarket.neg(),\n            blockTime\n        );\n\n        netSyToAccount = _netSyToAccount.Uint();\n        netSyFee = _netSyFee.Uint();\n        netSyToReserve = _netSyToReserve.Uint();\n    }\n\n    function swapSyForExactPt(\n        MarketState memory market,\n        PYIndex index,\n        uint256 exactPtToAccount,\n        uint256 blockTime\n    ) internal pure returns (uint256 netSyToMarket, uint256 netSyFee, uint256 netSyToReserve) {\n        (int256 _netSyToAccount, int256 _netSyFee, int256 _netSyToReserve) = executeTradeCore(\n            market,\n            index,\n            exactPtToAccount.Int(),\n            blockTime\n        );\n\n        netSyToMarket = _netSyToAccount.neg().Uint();\n        netSyFee = _netSyFee.Uint();\n        netSyToReserve = _netSyToReserve.Uint();\n    }\n\n    /*///////////////////////////////////////////////////////////////\n                    CORE FUNCTIONS\n    //////////////////////////////////////////////////////////////*/\n\n    function addLiquidityCore(\n        MarketState memory market,\n        int256 syDesired,\n        int256 ptDesired,\n        uint256 blockTime\n    ) internal pure returns (int256 lpToReserve, int256 lpToAccount, int256 syUsed, int256 ptUsed) {\n        /// ------------------------------------------------------------\n        /// CHECKS\n        /// ------------------------------------------------------------\n        if (syDesired == 0 || ptDesired == 0) revert Errors.MarketZeroAmountsInput();\n        if (MiniHelpers.isExpired(market.expiry, blockTime)) revert Errors.MarketExpired();\n\n        /// ------------------------------------------------------------\n        /// MATH\n        /// ------------------------------------------------------------\n        if (market.totalLp == 0) {\n            lpToAccount = PMath.sqrt((syDesired * ptDesired).Uint()).Int() - MINIMUM_LIQUIDITY;\n            lpToReserve = MINIMUM_LIQUIDITY;\n            syUsed = syDesired;\n            ptUsed = ptDesired;\n        } else {\n            int256 netLpByPt = (ptDesired * market.totalLp) / market.totalPt;\n            int256 netLpBySy = (syDesired * market.totalLp) / market.totalSy;\n            if (netLpByPt < netLpBySy) {\n                lpToAccount = netLpByPt;\n                ptUsed = ptDesired;\n                syUsed = (market.totalSy * lpToAccount).rawDivUp(market.totalLp);\n            } else {\n                lpToAccount = netLpBySy;\n                syUsed = syDesired;\n                ptUsed = (market.totalPt * lpToAccount).rawDivUp(market.totalLp);\n            }\n        }\n\n        if (lpToAccount <= 0 || syUsed <= 0 || ptUsed <= 0) revert Errors.MarketZeroAmountsOutput();\n\n        /// ------------------------------------------------------------\n        /// WRITE\n        /// ------------------------------------------------------------\n        market.totalSy += syUsed;\n        market.totalPt += ptUsed;\n        market.totalLp += lpToAccount + lpToReserve;\n    }\n\n    function removeLiquidityCore(\n        MarketState memory market,\n        int256 lpToRemove\n    ) internal pure returns (int256 netSyToAccount, int256 netPtToAccount) {\n        /// ------------------------------------------------------------\n        /// CHECKS\n        /// ------------------------------------------------------------\n        if (lpToRemove == 0) revert Errors.MarketZeroAmountsInput();\n\n        /// ------------------------------------------------------------\n        /// MATH\n        /// ------------------------------------------------------------\n        netSyToAccount = (lpToRemove * market.totalSy) / market.totalLp;\n        netPtToAccount = (lpToRemove * market.totalPt) / market.totalLp;\n\n        if (netSyToAccount == 0 && netPtToAccount == 0) revert Errors.MarketZeroAmountsOutput();\n\n        /// ------------------------------------------------------------\n        /// WRITE\n        /// ------------------------------------------------------------\n        market.totalLp = market.totalLp.subNoNeg(lpToRemove);\n        market.totalPt = market.totalPt.subNoNeg(netPtToAccount);\n        market.totalSy = market.totalSy.subNoNeg(netSyToAccount);\n    }\n\n    function executeTradeCore(\n        MarketState memory market,\n        PYIndex index,\n        int256 netPtToAccount,\n        uint256 blockTime\n    ) internal pure returns (int256 netSyToAccount, int256 netSyFee, int256 netSyToReserve) {\n        /// ------------------------------------------------------------\n        /// CHECKS\n        /// ------------------------------------------------------------\n        if (MiniHelpers.isExpired(market.expiry, blockTime)) revert Errors.MarketExpired();\n        if (market.totalPt <= netPtToAccount)\n            revert Errors.MarketInsufficientPtForTrade(market.totalPt, netPtToAccount);\n\n        /// ------------------------------------------------------------\n        /// MATH\n        /// ------------------------------------------------------------\n        MarketPreCompute memory comp = getMarketPreCompute(market, index, blockTime);\n\n        (netSyToAccount, netSyFee, netSyToReserve) = calcTrade(market, comp, index, netPtToAccount);\n\n        /// ------------------------------------------------------------\n        /// WRITE\n        /// ------------------------------------------------------------\n        _setNewMarketStateTrade(market, comp, index, netPtToAccount, netSyToAccount, netSyToReserve, blockTime);\n    }\n\n    function getMarketPreCompute(\n        MarketState memory market,\n        PYIndex index,\n        uint256 blockTime\n    ) internal pure returns (MarketPreCompute memory res) {\n        if (MiniHelpers.isExpired(market.expiry, blockTime)) revert Errors.MarketExpired();\n\n        uint256 timeToExpiry = market.expiry - blockTime;\n\n        res.rateScalar = _getRateScalar(market, timeToExpiry);\n        res.totalAsset = index.syToAsset(market.totalSy);\n\n        if (market.totalPt == 0 || res.totalAsset == 0)\n            revert Errors.MarketZeroTotalPtOrTotalAsset(market.totalPt, res.totalAsset);\n\n        res.rateAnchor = _getRateAnchor(\n            market.totalPt,\n            market.lastLnImpliedRate,\n            res.totalAsset,\n            res.rateScalar,\n            timeToExpiry\n        );\n        res.feeRate = _getExchangeRateFromImpliedRate(market.lnFeeRateRoot, timeToExpiry);\n    }\n\n    function calcTrade(\n        MarketState memory market,\n        MarketPreCompute memory comp,\n        PYIndex index,\n        int256 netPtToAccount\n    ) internal pure returns (int256 netSyToAccount, int256 netSyFee, int256 netSyToReserve) {\n        int256 preFeeExchangeRate = _getExchangeRate(\n            market.totalPt,\n            comp.totalAsset,\n            comp.rateScalar,\n            comp.rateAnchor,\n            netPtToAccount\n        );\n\n        int256 preFeeAssetToAccount = netPtToAccount.divDown(preFeeExchangeRate).neg();\n        int256 fee = comp.feeRate;\n\n        if (netPtToAccount > 0) {\n            int256 postFeeExchangeRate = preFeeExchangeRate.divDown(fee);\n            if (postFeeExchangeRate < PMath.IONE) revert Errors.MarketExchangeRateBelowOne(postFeeExchangeRate);\n\n            fee = preFeeAssetToAccount.mulDown(PMath.IONE - fee);\n        } else {\n            fee = ((preFeeAssetToAccount * (PMath.IONE - fee)) / fee).neg();\n        }\n\n        int256 netAssetToReserve = (fee * market.reserveFeePercent.Int()) / PERCENTAGE_DECIMALS;\n        int256 netAssetToAccount = preFeeAssetToAccount - fee;\n\n        netSyToAccount = netAssetToAccount < 0\n            ? index.assetToSyUp(netAssetToAccount)\n            : index.assetToSy(netAssetToAccount);\n        netSyFee = index.assetToSy(fee);\n        netSyToReserve = index.assetToSy(netAssetToReserve);\n    }\n\n    function _setNewMarketStateTrade(\n        MarketState memory market,\n        MarketPreCompute memory comp,\n        PYIndex index,\n        int256 netPtToAccount,\n        int256 netSyToAccount,\n        int256 netSyToReserve,\n        uint256 blockTime\n    ) internal pure {\n        uint256 timeToExpiry = market.expiry - blockTime;\n\n        market.totalPt = market.totalPt.subNoNeg(netPtToAccount);\n        market.totalSy = market.totalSy.subNoNeg(netSyToAccount + netSyToReserve);\n\n        market.lastLnImpliedRate = _getLnImpliedRate(\n            market.totalPt,\n            index.syToAsset(market.totalSy),\n            comp.rateScalar,\n            comp.rateAnchor,\n            timeToExpiry\n        );\n\n        if (market.lastLnImpliedRate == 0) revert Errors.MarketZeroLnImpliedRate();\n    }\n\n    function _getRateAnchor(\n        int256 totalPt,\n        uint256 lastLnImpliedRate,\n        int256 totalAsset,\n        int256 rateScalar,\n        uint256 timeToExpiry\n    ) internal pure returns (int256 rateAnchor) {\n        int256 newExchangeRate = _getExchangeRateFromImpliedRate(lastLnImpliedRate, timeToExpiry);\n\n        if (newExchangeRate < PMath.IONE) revert Errors.MarketExchangeRateBelowOne(newExchangeRate);\n\n        {\n            int256 proportion = totalPt.divDown(totalPt + totalAsset);\n\n            int256 lnProportion = _logProportion(proportion);\n\n            rateAnchor = newExchangeRate - lnProportion.divDown(rateScalar);\n        }\n    }\n\n    /// @notice Calculates the current market implied rate.\n    /// @return lnImpliedRate the implied rate\n    function _getLnImpliedRate(\n        int256 totalPt,\n        int256 totalAsset,\n        int256 rateScalar,\n        int256 rateAnchor,\n        uint256 timeToExpiry\n    ) internal pure returns (uint256 lnImpliedRate) {\n        // This will check for exchange rates < PMath.IONE\n        int256 exchangeRate = _getExchangeRate(totalPt, totalAsset, rateScalar, rateAnchor, 0);\n\n        // exchangeRate >= 1 so its ln >= 0\n        uint256 lnRate = exchangeRate.ln().Uint();\n\n        lnImpliedRate = (lnRate * IMPLIED_RATE_TIME) / timeToExpiry;\n    }\n\n    /// @notice Converts an implied rate to an exchange rate given a time to expiry. The\n    /// formula is E = e^rt\n    function _getExchangeRateFromImpliedRate(\n        uint256 lnImpliedRate,\n        uint256 timeToExpiry\n    ) internal pure returns (int256 exchangeRate) {\n        uint256 rt = (lnImpliedRate * timeToExpiry) / IMPLIED_RATE_TIME;\n\n        exchangeRate = LogExpMath.exp(rt.Int());\n    }\n\n    function _getExchangeRate(\n        int256 totalPt,\n        int256 totalAsset,\n        int256 rateScalar,\n        int256 rateAnchor,\n        int256 netPtToAccount\n    ) internal pure returns (int256 exchangeRate) {\n        int256 numerator = totalPt.subNoNeg(netPtToAccount);\n\n        int256 proportion = (numerator.divDown(totalPt + totalAsset));\n\n        if (proportion > MAX_MARKET_PROPORTION)\n            revert Errors.MarketProportionTooHigh(proportion, MAX_MARKET_PROPORTION);\n\n        int256 lnProportion = _logProportion(proportion);\n\n        exchangeRate = lnProportion.divDown(rateScalar) + rateAnchor;\n\n        if (exchangeRate < PMath.IONE) revert Errors.MarketExchangeRateBelowOne(exchangeRate);\n    }\n\n    function _logProportion(int256 proportion) internal pure returns (int256 res) {\n        if (proportion == PMath.IONE) revert Errors.MarketProportionMustNotEqualOne();\n\n        int256 logitP = proportion.divDown(PMath.IONE - proportion);\n\n        res = logitP.ln();\n    }\n\n    function _getRateScalar(MarketState memory market, uint256 timeToExpiry) internal pure returns (int256 rateScalar) {\n        rateScalar = (market.scalarRoot * IMPLIED_RATE_TIME.Int()) / timeToExpiry.Int();\n        if (rateScalar <= 0) revert Errors.MarketRateScalarBelowZero(rateScalar);\n    }\n\n    function setInitialLnImpliedRate(\n        MarketState memory market,\n        PYIndex index,\n        int256 initialAnchor,\n        uint256 blockTime\n    ) internal pure {\n        /// ------------------------------------------------------------\n        /// CHECKS\n        /// ------------------------------------------------------------\n        if (MiniHelpers.isExpired(market.expiry, blockTime)) revert Errors.MarketExpired();\n\n        /// ------------------------------------------------------------\n        /// MATH\n        /// ------------------------------------------------------------\n        int256 totalAsset = index.syToAsset(market.totalSy);\n        uint256 timeToExpiry = market.expiry - blockTime;\n        int256 rateScalar = _getRateScalar(market, timeToExpiry);\n\n        /// ------------------------------------------------------------\n        /// WRITE\n        /// ------------------------------------------------------------\n        market.lastLnImpliedRate = _getLnImpliedRate(\n            market.totalPt,\n            totalAsset,\n            rateScalar,\n            initialAnchor,\n            timeToExpiry\n        );\n    }\n}\n"},{"file_path":"contracts/core/StandardizedYield/PYIndex.sol","source_code":"// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity ^0.8.0;\nimport \"../../interfaces/IPYieldToken.sol\";\nimport \"../../interfaces/IPPrincipalToken.sol\";\n\nimport \"./SYUtils.sol\";\nimport \"../libraries/math/PMath.sol\";\n\ntype PYIndex is uint256;\n\nlibrary PYIndexLib {\n    using PMath for uint256;\n    using PMath for int256;\n\n    function newIndex(IPYieldToken YT) internal returns (PYIndex) {\n        return PYIndex.wrap(YT.pyIndexCurrent());\n    }\n\n    function syToAsset(PYIndex index, uint256 syAmount) internal pure returns (uint256) {\n        return SYUtils.syToAsset(PYIndex.unwrap(index), syAmount);\n    }\n\n    function assetToSy(PYIndex index, uint256 assetAmount) internal pure returns (uint256) {\n        return SYUtils.assetToSy(PYIndex.unwrap(index), assetAmount);\n    }\n\n    function assetToSyUp(PYIndex index, uint256 assetAmount) internal pure returns (uint256) {\n        return SYUtils.assetToSyUp(PYIndex.unwrap(index), assetAmount);\n    }\n\n    function syToAssetUp(PYIndex index, uint256 syAmount) internal pure returns (uint256) {\n        uint256 _index = PYIndex.unwrap(index);\n        return SYUtils.syToAssetUp(_index, syAmount);\n    }\n\n    function syToAsset(PYIndex index, int256 syAmount) internal pure returns (int256) {\n        int256 sign = syAmount < 0 ? int256(-1) : int256(1);\n        return sign * (SYUtils.syToAsset(PYIndex.unwrap(index), syAmount.abs())).Int();\n    }\n\n    function assetToSy(PYIndex index, int256 assetAmount) internal pure returns (int256) {\n        int256 sign = assetAmount < 0 ? int256(-1) : int256(1);\n        return sign * (SYUtils.assetToSy(PYIndex.unwrap(index), assetAmount.abs())).Int();\n    }\n\n    function assetToSyUp(PYIndex index, int256 assetAmount) internal pure returns (int256) {\n        int256 sign = assetAmount < 0 ? int256(-1) : int256(1);\n        return sign * (SYUtils.assetToSyUp(PYIndex.unwrap(index), assetAmount.abs())).Int();\n    }\n}\n"},{"file_path":"contracts/core/StandardizedYield/SYUtils.sol","source_code":"// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity ^0.8.0;\n\nlibrary SYUtils {\n    uint256 internal constant ONE = 1e18;\n\n    function syToAsset(uint256 exchangeRate, uint256 syAmount) internal pure returns (uint256) {\n        return (syAmount * exchangeRate) / ONE;\n    }\n\n    function syToAssetUp(uint256 exchangeRate, uint256 syAmount) internal pure returns (uint256) {\n        return (syAmount * exchangeRate + ONE - 1) / ONE;\n    }\n\n    function assetToSy(uint256 exchangeRate, uint256 assetAmount) internal pure returns (uint256) {\n        return (assetAmount * ONE) / exchangeRate;\n    }\n\n    function assetToSyUp(uint256 exchangeRate, uint256 assetAmount) internal pure returns (uint256) {\n        return (assetAmount * ONE + exchangeRate - 1) / exchangeRate;\n    }\n}\n"},{"file_path":"contracts/core/libraries/Errors.sol","source_code":"// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity ^0.8.0;\n\nlibrary Errors {\n    // BulkSeller\n    error BulkInsufficientSyForTrade(uint256 currentAmount, uint256 requiredAmount);\n    error BulkInsufficientTokenForTrade(uint256 currentAmount, uint256 requiredAmount);\n    error BulkInSufficientSyOut(uint256 actualSyOut, uint256 requiredSyOut);\n    error BulkInSufficientTokenOut(uint256 actualTokenOut, uint256 requiredTokenOut);\n    error BulkInsufficientSyReceived(uint256 actualBalance, uint256 requiredBalance);\n    error BulkNotMaintainer();\n    error BulkNotAdmin();\n    error BulkSellerAlreadyExisted(address token, address SY, address bulk);\n    error BulkSellerInvalidToken(address token, address SY);\n    error BulkBadRateTokenToSy(uint256 actualRate, uint256 currentRate, uint256 eps);\n    error BulkBadRateSyToToken(uint256 actualRate, uint256 currentRate, uint256 eps);\n\n    // APPROX\n    error ApproxFail();\n    error ApproxParamsInvalid(uint256 guessMin, uint256 guessMax, uint256 eps);\n    error ApproxBinarySearchInputInvalid(\n        uint256 approxGuessMin,\n        uint256 approxGuessMax,\n        uint256 minGuessMin,\n        uint256 maxGuessMax\n    );\n\n    // MARKET + MARKET MATH CORE\n    error MarketExpired();\n    error MarketZeroAmountsInput();\n    error MarketZeroAmountsOutput();\n    error MarketZeroLnImpliedRate();\n    error MarketInsufficientPtForTrade(int256 currentAmount, int256 requiredAmount);\n    error MarketInsufficientPtReceived(uint256 actualBalance, uint256 requiredBalance);\n    error MarketInsufficientSyReceived(uint256 actualBalance, uint256 requiredBalance);\n    error MarketZeroTotalPtOrTotalAsset(int256 totalPt, int256 totalAsset);\n    error MarketExchangeRateBelowOne(int256 exchangeRate);\n    error MarketProportionMustNotEqualOne();\n    error MarketRateScalarBelowZero(int256 rateScalar);\n    error MarketScalarRootBelowZero(int256 scalarRoot);\n    error MarketProportionTooHigh(int256 proportion, int256 maxProportion);\n\n    error OracleUninitialized();\n    error OracleTargetTooOld(uint32 target, uint32 oldest);\n    error OracleZeroCardinality();\n\n    error MarketFactoryExpiredPt();\n    error MarketFactoryInvalidPt();\n    error MarketFactoryMarketExists();\n\n    error MarketFactoryLnFeeRateRootTooHigh(uint80 lnFeeRateRoot, uint256 maxLnFeeRateRoot);\n    error MarketFactoryOverriddenFeeTooHigh(uint80 overriddenFee, uint256 marketLnFeeRateRoot);\n    error MarketFactoryReserveFeePercentTooHigh(uint8 reserveFeePercent, uint8 maxReserveFeePercent);\n    error MarketFactoryZeroTreasury();\n    error MarketFactoryInitialAnchorTooLow(int256 initialAnchor, int256 minInitialAnchor);\n    error MFNotPendleMarket(address addr);\n\n    // ROUTER\n    error RouterInsufficientLpOut(uint256 actualLpOut, uint256 requiredLpOut);\n    error RouterInsufficientSyOut(uint256 actualSyOut, uint256 requiredSyOut);\n    error RouterInsufficientPtOut(uint256 actualPtOut, uint256 requiredPtOut);\n    error RouterInsufficientYtOut(uint256 actualYtOut, uint256 requiredYtOut);\n    error RouterInsufficientPYOut(uint256 actualPYOut, uint256 requiredPYOut);\n    error RouterInsufficientTokenOut(uint256 actualTokenOut, uint256 requiredTokenOut);\n    error RouterInsufficientSyRepay(uint256 actualSyRepay, uint256 requiredSyRepay);\n    error RouterInsufficientPtRepay(uint256 actualPtRepay, uint256 requiredPtRepay);\n    error RouterNotAllSyUsed(uint256 netSyDesired, uint256 netSyUsed);\n\n    error RouterTimeRangeZero();\n    error RouterCallbackNotPendleMarket(address caller);\n    error RouterInvalidAction(bytes4 selector);\n    error RouterInvalidFacet(address facet);\n\n    error RouterKyberSwapDataZero();\n\n    error SimulationResults(bool success, bytes res);\n\n    // YIELD CONTRACT\n    error YCExpired();\n    error YCNotExpired();\n    error YieldContractInsufficientSy(uint256 actualSy, uint256 requiredSy);\n    error YCNothingToRedeem();\n    error YCPostExpiryDataNotSet();\n    error YCNoFloatingSy();\n\n    // YieldFactory\n    error YCFactoryInvalidExpiry();\n    error YCFactoryYieldContractExisted();\n    error YCFactoryZeroExpiryDivisor();\n    error YCFactoryZeroTreasury();\n    error YCFactoryInterestFeeRateTooHigh(uint256 interestFeeRate, uint256 maxInterestFeeRate);\n    error YCFactoryRewardFeeRateTooHigh(uint256 newRewardFeeRate, uint256 maxRewardFeeRate);\n\n    // SY\n    error SYInvalidTokenIn(address token);\n    error SYInvalidTokenOut(address token);\n    error SYZeroDeposit();\n    error SYZeroRedeem();\n    error SYInsufficientSharesOut(uint256 actualSharesOut, uint256 requiredSharesOut);\n    error SYInsufficientTokenOut(uint256 actualTokenOut, uint256 requiredTokenOut);\n\n    // SY-specific\n    error SYQiTokenMintFailed(uint256 errCode);\n    error SYQiTokenRedeemFailed(uint256 errCode);\n    error SYQiTokenRedeemRewardsFailed(uint256 rewardAccruedType0, uint256 rewardAccruedType1);\n    error SYQiTokenBorrowRateTooHigh(uint256 borrowRate, uint256 borrowRateMax);\n\n    error SYCurveInvalidPid();\n    error SYCurve3crvPoolNotFound();\n\n    error SYApeDepositAmountTooSmall(uint256 amountDeposited);\n    error SYBalancerInvalidPid();\n    error SYInvalidRewardToken(address token);\n\n    error SYStargateRedeemCapExceeded(uint256 amountLpDesired, uint256 amountLpRedeemable);\n\n    error SYBalancerReentrancy();\n\n    error NotFromTrustedRemote(uint16 srcChainId, bytes path);\n\n    error ApxETHNotEnoughBuffer();\n\n    // Liquidity Mining\n    error VCInactivePool(address pool);\n    error VCPoolAlreadyActive(address pool);\n    error VCZeroVePendle(address user);\n    error VCExceededMaxWeight(uint256 totalWeight, uint256 maxWeight);\n    error VCEpochNotFinalized(uint256 wTime);\n    error VCPoolAlreadyAddAndRemoved(address pool);\n\n    error VEInvalidNewExpiry(uint256 newExpiry);\n    error VEExceededMaxLockTime();\n    error VEInsufficientLockTime();\n    error VENotAllowedReduceExpiry();\n    error VEZeroAmountLocked();\n    error VEPositionNotExpired();\n    error VEZeroPosition();\n    error VEZeroSlope(uint128 bias, uint128 slope);\n    error VEReceiveOldSupply(uint256 msgTime);\n\n    error GCNotPendleMarket(address caller);\n    error GCNotVotingController(address caller);\n\n    error InvalidWTime(uint256 wTime);\n    error ExpiryInThePast(uint256 expiry);\n    error ChainNotSupported(uint256 chainId);\n\n    error FDTotalAmountFundedNotMatch(uint256 actualTotalAmount, uint256 expectedTotalAmount);\n    error FDEpochLengthMismatch();\n    error FDInvalidPool(address pool);\n    error FDPoolAlreadyExists(address pool);\n    error FDInvalidNewFinishedEpoch(uint256 oldFinishedEpoch, uint256 newFinishedEpoch);\n    error FDInvalidStartEpoch(uint256 startEpoch);\n    error FDInvalidWTimeFund(uint256 lastFunded, uint256 wTime);\n    error FDFutureFunding(uint256 lastFunded, uint256 currentWTime);\n\n    error BDInvalidEpoch(uint256 epoch, uint256 startTime);\n\n    // Cross-Chain\n    error MsgNotFromSendEndpoint(uint16 srcChainId, bytes path);\n    error MsgNotFromReceiveEndpoint(address sender);\n    error InsufficientFeeToSendMsg(uint256 currentFee, uint256 requiredFee);\n    error ApproxDstExecutionGasNotSet();\n    error InvalidRetryData();\n\n    // GENERIC MSG\n    error ArrayLengthMismatch();\n    error ArrayEmpty();\n    error ArrayOutOfBounds();\n    error ZeroAddress();\n    error FailedToSendEther();\n    error InvalidMerkleProof();\n\n    error OnlyLayerZeroEndpoint();\n    error OnlyYT();\n    error OnlyYCFactory();\n    error OnlyWhitelisted();\n\n    // Swap Aggregator\n    error SAInsufficientTokenIn(address tokenIn, uint256 amountExpected, uint256 amountActual);\n    error UnsupportedSelector(uint256 aggregatorType, bytes4 selector);\n}\n"},{"file_path":"contracts/core/libraries/MiniHelpers.sol","source_code":"// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity ^0.8.0;\n\nlibrary MiniHelpers {\n    function isCurrentlyExpired(uint256 expiry) internal view returns (bool) {\n        return (expiry <= block.timestamp);\n    }\n\n    function isExpired(uint256 expiry, uint256 blockTime) internal pure returns (bool) {\n        return (expiry <= blockTime);\n    }\n\n    function isTimeInThePast(uint256 timestamp) internal view returns (bool) {\n        return (timestamp <= block.timestamp); // same definition as isCurrentlyExpired\n    }\n}\n"},{"file_path":"contracts/core/libraries/math/LogExpMath.sol","source_code":"// SPDX-License-Identifier: GPL-3.0-or-later\n// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated\n// documentation files (the “Software”), to deal in the Software without restriction, including without limitation the\n// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to\n// permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\n// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the\n// Software.\n\n// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE\n// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\npragma solidity ^0.8.0;\n\n/* solhint-disable */\n\n/**\n * @dev Exponentiation and logarithm functions for 18 decimal fixed point numbers (both base and exponent/argument).\n *\n * Exponentiation and logarithm with arbitrary bases (x^y and log_x(y)) are implemented by conversion to natural\n * exponentiation and logarithm (where the base is Euler's number).\n *\n * @author Fernando Martinelli - @fernandomartinelli\n * @author Sergio Yuhjtman - @sergioyuhjtman\n * @author Daniel Fernandez - @dmf7z\n */\nlibrary LogExpMath {\n    // All fixed point multiplications and divisions are inlined. This means we need to divide by ONE when multiplying\n    // two numbers, and multiply by ONE when dividing them.\n\n    // All arguments and return values are 18 decimal fixed point numbers.\n    int256 constant ONE_18 = 1e18;\n\n    // Internally, intermediate values are computed with higher precision as 20 decimal fixed point numbers, and in the\n    // case of ln36, 36 decimals.\n    int256 constant ONE_20 = 1e20;\n    int256 constant ONE_36 = 1e36;\n\n    // The domain of natural exponentiation is bound by the word size and number of decimals used.\n    //\n    // Because internally the result will be stored using 20 decimals, the largest possible result is\n    // (2^255 - 1) / 10^20, which makes the largest exponent ln((2^255 - 1) / 10^20) = 130.700829182905140221.\n    // The smallest possible result is 10^(-18), which makes largest negative argument\n    // ln(10^(-18)) = -41.446531673892822312.\n    // We use 130.0 and -41.0 to have some safety margin.\n    int256 constant MAX_NATURAL_EXPONENT = 130e18;\n    int256 constant MIN_NATURAL_EXPONENT = -41e18;\n\n    // Bounds for ln_36's argument. Both ln(0.9) and ln(1.1) can be represented with 36 decimal places in a fixed point\n    // 256 bit integer.\n    int256 constant LN_36_LOWER_BOUND = ONE_18 - 1e17;\n    int256 constant LN_36_UPPER_BOUND = ONE_18 + 1e17;\n\n    uint256 constant MILD_EXPONENT_BOUND = 2 ** 254 / uint256(ONE_20);\n\n    // 18 decimal constants\n    int256 constant x0 = 128000000000000000000; // 2ˆ7\n    int256 constant a0 = 38877084059945950922200000000000000000000000000000000000; // eˆ(x0) (no decimals)\n    int256 constant x1 = 64000000000000000000; // 2ˆ6\n    int256 constant a1 = 6235149080811616882910000000; // eˆ(x1) (no decimals)\n\n    // 20 decimal constants\n    int256 constant x2 = 3200000000000000000000; // 2ˆ5\n    int256 constant a2 = 7896296018268069516100000000000000; // eˆ(x2)\n    int256 constant x3 = 1600000000000000000000; // 2ˆ4\n    int256 constant a3 = 888611052050787263676000000; // eˆ(x3)\n    int256 constant x4 = 800000000000000000000; // 2ˆ3\n    int256 constant a4 = 298095798704172827474000; // eˆ(x4)\n    int256 constant x5 = 400000000000000000000; // 2ˆ2\n    int256 constant a5 = 5459815003314423907810; // eˆ(x5)\n    int256 constant x6 = 200000000000000000000; // 2ˆ1\n    int256 constant a6 = 738905609893065022723; // eˆ(x6)\n    int256 constant x7 = 100000000000000000000; // 2ˆ0\n    int256 constant a7 = 271828182845904523536; // eˆ(x7)\n    int256 constant x8 = 50000000000000000000; // 2ˆ-1\n    int256 constant a8 = 164872127070012814685; // eˆ(x8)\n    int256 constant x9 = 25000000000000000000; // 2ˆ-2\n    int256 constant a9 = 128402541668774148407; // eˆ(x9)\n    int256 constant x10 = 12500000000000000000; // 2ˆ-3\n    int256 constant a10 = 113314845306682631683; // eˆ(x10)\n    int256 constant x11 = 6250000000000000000; // 2ˆ-4\n    int256 constant a11 = 106449445891785942956; // eˆ(x11)\n\n    /**\n     * @dev Natural exponentiation (e^x) with signed 18 decimal fixed point exponent.\n     *\n     * Reverts if `x` is smaller than MIN_NATURAL_EXPONENT, or larger than `MAX_NATURAL_EXPONENT`.\n     */\n    function exp(int256 x) internal pure returns (int256) {\n        unchecked {\n            require(x >= MIN_NATURAL_EXPONENT && x <= MAX_NATURAL_EXPONENT, \"Invalid exponent\");\n\n            if (x < 0) {\n                // We only handle positive exponents: e^(-x) is computed as 1 / e^x. We can safely make x positive since it\n                // fits in the signed 256 bit range (as it is larger than MIN_NATURAL_EXPONENT).\n                // Fixed point division requires multiplying by ONE_18.\n                return ((ONE_18 * ONE_18) / exp(-x));\n            }\n\n            // First, we use the fact that e^(x+y) = e^x * e^y to decompose x into a sum of powers of two, which we call x_n,\n            // where x_n == 2^(7 - n), and e^x_n = a_n has been precomputed. We choose the first x_n, x0, to equal 2^7\n            // because all larger powers are larger than MAX_NATURAL_EXPONENT, and therefore not present in the\n            // decomposition.\n            // At the end of this process we will have the product of all e^x_n = a_n that apply, and the remainder of this\n            // decomposition, which will be lower than the smallest x_n.\n            // exp(x) = k_0 * a_0 * k_1 * a_1 * ... + k_n * a_n * exp(remainder), where each k_n equals either 0 or 1.\n            // We mutate x by subtracting x_n, making it the remainder of the decomposition.\n\n            // The first two a_n (e^(2^7) and e^(2^6)) are too large if stored as 18 decimal numbers, and could cause\n            // intermediate overflows. Instead we store them as plain integers, with 0 decimals.\n            // Additionally, x0 + x1 is larger than MAX_NATURAL_EXPONENT, which means they will not both be present in the\n            // decomposition.\n\n            // For each x_n, we test if that term is present in the decomposition (if x is larger than it), and if so deduct\n            // it and compute the accumulated product.\n\n            int256 firstAN;\n            if (x >= x0) {\n                x -= x0;\n                firstAN = a0;\n            } else if (x >= x1) {\n                x -= x1;\n                firstAN = a1;\n            } else {\n                firstAN = 1; // One with no decimal places\n            }\n\n            // We now transform x into a 20 decimal fixed point number, to have enhanced precision when computing the\n            // smaller terms.\n            x *= 100;\n\n            // `product` is the accumulated product of all a_n (except a0 and a1), which starts at 20 decimal fixed point\n            // one. Recall that fixed point multiplication requires dividing by ONE_20.\n            int256 product = ONE_20;\n\n            if (x >= x2) {\n                x -= x2;\n                product = (product * a2) / ONE_20;\n            }\n            if (x >= x3) {\n                x -= x3;\n                product = (product * a3) / ONE_20;\n            }\n            if (x >= x4) {\n                x -= x4;\n                product = (product * a4) / ONE_20;\n            }\n            if (x >= x5) {\n                x -= x5;\n                product = (product * a5) / ONE_20;\n            }\n            if (x >= x6) {\n                x -= x6;\n                product = (product * a6) / ONE_20;\n            }\n            if (x >= x7) {\n                x -= x7;\n                product = (product * a7) / ONE_20;\n            }\n            if (x >= x8) {\n                x -= x8;\n                product = (product * a8) / ONE_20;\n            }\n            if (x >= x9) {\n                x -= x9;\n                product = (product * a9) / ONE_20;\n            }\n\n            // x10 and x11 are unnecessary here since we have high enough precision already.\n\n            // Now we need to compute e^x, where x is small (in particular, it is smaller than x9). We use the Taylor series\n            // expansion for e^x: 1 + x + (x^2 / 2!) + (x^3 / 3!) + ... + (x^n / n!).\n\n            int256 seriesSum = ONE_20; // The initial one in the sum, with 20 decimal places.\n            int256 term; // Each term in the sum, where the nth term is (x^n / n!).\n\n            // The first term is simply x.\n            term = x;\n            seriesSum += term;\n\n            // Each term (x^n / n!) equals the previous one times x, divided by n. Since x is a fixed point number,\n            // multiplying by it requires dividing by ONE_20, but dividing by the non-fixed point n values does not.\n\n            term = ((term * x) / ONE_20) / 2;\n            seriesSum += term;\n\n            term = ((term * x) / ONE_20) / 3;\n            seriesSum += term;\n\n            term = ((term * x) / ONE_20) / 4;\n            seriesSum += term;\n\n            term = ((term * x) / ONE_20) / 5;\n            seriesSum += term;\n\n            term = ((term * x) / ONE_20) / 6;\n            seriesSum += term;\n\n            term = ((term * x) / ONE_20) / 7;\n            seriesSum += term;\n\n            term = ((term * x) / ONE_20) / 8;\n            seriesSum += term;\n\n            term = ((term * x) / ONE_20) / 9;\n            seriesSum += term;\n\n            term = ((term * x) / ONE_20) / 10;\n            seriesSum += term;\n\n            term = ((term * x) / ONE_20) / 11;\n            seriesSum += term;\n\n            term = ((term * x) / ONE_20) / 12;\n            seriesSum += term;\n\n            // 12 Taylor terms are sufficient for 18 decimal precision.\n\n            // We now have the first a_n (with no decimals), and the product of all other a_n present, and the Taylor\n            // approximation of the exponentiation of the remainder (both with 20 decimals). All that remains is to multiply\n            // all three (one 20 decimal fixed point multiplication, dividing by ONE_20, and one integer multiplication),\n            // and then drop two digits to return an 18 decimal value.\n\n            return (((product * seriesSum) / ONE_20) * firstAN) / 100;\n        }\n    }\n\n    /**\n     * @dev Natural logarithm (ln(a)) with signed 18 decimal fixed point argument.\n     */\n    function ln(int256 a) internal pure returns (int256) {\n        unchecked {\n            // The real natural logarithm is not defined for negative numbers or zero.\n            require(a > 0, \"out of bounds\");\n            if (LN_36_LOWER_BOUND < a && a < LN_36_UPPER_BOUND) {\n                return _ln_36(a) / ONE_18;\n            } else {\n                return _ln(a);\n            }\n        }\n    }\n\n    /**\n     * @dev Exponentiation (x^y) with unsigned 18 decimal fixed point base and exponent.\n     *\n     * Reverts if ln(x) * y is smaller than `MIN_NATURAL_EXPONENT`, or larger than `MAX_NATURAL_EXPONENT`.\n     */\n    function pow(uint256 x, uint256 y) internal pure returns (uint256) {\n        unchecked {\n            if (y == 0) {\n                // We solve the 0^0 indetermination by making it equal one.\n                return uint256(ONE_18);\n            }\n\n            if (x == 0) {\n                return 0;\n            }\n\n            // Instead of computing x^y directly, we instead rely on the properties of logarithms and exponentiation to\n            // arrive at that r`esult. In particular, exp(ln(x)) = x, and ln(x^y) = y * ln(x). This means\n            // x^y = exp(y * ln(x)).\n\n            // The ln function takes a signed value, so we need to make sure x fits in the signed 256 bit range.\n            require(x < 2 ** 255, \"x out of bounds\");\n            int256 x_int256 = int256(x);\n\n            // We will compute y * ln(x) in a single step. Depending on the value of x, we can either use ln or ln_36. In\n            // both cases, we leave the division by ONE_18 (due to fixed point multiplication) to the end.\n\n            // This prevents y * ln(x) from overflowing, and at the same time guarantees y fits in the signed 256 bit range.\n            require(y < MILD_EXPONENT_BOUND, \"y out of bounds\");\n            int256 y_int256 = int256(y);\n\n            int256 logx_times_y;\n            if (LN_36_LOWER_BOUND < x_int256 && x_int256 < LN_36_UPPER_BOUND) {\n                int256 ln_36_x = _ln_36(x_int256);\n\n                // ln_36_x has 36 decimal places, so multiplying by y_int256 isn't as straightforward, since we can't just\n                // bring y_int256 to 36 decimal places, as it might overflow. Instead, we perform two 18 decimal\n                // multiplications and add the results: one with the first 18 decimals of ln_36_x, and one with the\n                // (downscaled) last 18 decimals.\n                logx_times_y = ((ln_36_x / ONE_18) * y_int256 + ((ln_36_x % ONE_18) * y_int256) / ONE_18);\n            } else {\n                logx_times_y = _ln(x_int256) * y_int256;\n            }\n            logx_times_y /= ONE_18;\n\n            // Finally, we compute exp(y * ln(x)) to arrive at x^y\n            require(\n                MIN_NATURAL_EXPONENT <= logx_times_y && logx_times_y <= MAX_NATURAL_EXPONENT,\n                \"product out of bounds\"\n            );\n\n            return uint256(exp(logx_times_y));\n        }\n    }\n\n    /**\n     * @dev Internal natural logarithm (ln(a)) with signed 18 decimal fixed point argument.\n     */\n    function _ln(int256 a) private pure returns (int256) {\n        unchecked {\n            if (a < ONE_18) {\n                // Since ln(a^k) = k * ln(a), we can compute ln(a) as ln(a) = ln((1/a)^(-1)) = - ln((1/a)). If a is less\n                // than one, 1/a will be greater than one, and this if statement will not be entered in the recursive call.\n                // Fixed point division requires multiplying by ONE_18.\n                return (-_ln((ONE_18 * ONE_18) / a));\n            }\n\n            // First, we use the fact that ln^(a * b) = ln(a) + ln(b) to decompose ln(a) into a sum of powers of two, which\n            // we call x_n, where x_n == 2^(7 - n), which are the natural logarithm of precomputed quantities a_n (that is,\n            // ln(a_n) = x_n). We choose the first x_n, x0, to equal 2^7 because the exponential of all larger powers cannot\n            // be represented as 18 fixed point decimal numbers in 256 bits, and are therefore larger than a.\n            // At the end of this process we will have the sum of all x_n = ln(a_n) that apply, and the remainder of this\n            // decomposition, which will be lower than the smallest a_n.\n            // ln(a) = k_0 * x_0 + k_1 * x_1 + ... + k_n * x_n + ln(remainder), where each k_n equals either 0 or 1.\n            // We mutate a by subtracting a_n, making it the remainder of the decomposition.\n\n            // For reasons related to how `exp` works, the first two a_n (e^(2^7) and e^(2^6)) are not stored as fixed point\n            // numbers with 18 decimals, but instead as plain integers with 0 decimals, so we need to multiply them by\n            // ONE_18 to convert them to fixed point.\n            // For each a_n, we test if that term is present in the decomposition (if a is larger than it), and if so divide\n            // by it and compute the accumulated sum.\n\n            int256 sum = 0;\n            if (a >= a0 * ONE_18) {\n                a /= a0; // Integer, not fixed point division\n                sum += x0;\n            }\n\n            if (a >= a1 * ONE_18) {\n                a /= a1; // Integer, not fixed point division\n                sum += x1;\n            }\n\n            // All other a_n and x_n are stored as 20 digit fixed point numbers, so we convert the sum and a to this format.\n            sum *= 100;\n            a *= 100;\n\n            // Because further a_n are  20 digit fixed point numbers, we multiply by ONE_20 when dividing by them.\n\n            if (a >= a2) {\n                a = (a * ONE_20) / a2;\n                sum += x2;\n            }\n\n            if (a >= a3) {\n                a = (a * ONE_20) / a3;\n                sum += x3;\n            }\n\n            if (a >= a4) {\n                a = (a * ONE_20) / a4;\n                sum += x4;\n            }\n\n            if (a >= a5) {\n                a = (a * ONE_20) / a5;\n                sum += x5;\n            }\n\n            if (a >= a6) {\n                a = (a * ONE_20) / a6;\n                sum += x6;\n            }\n\n            if (a >= a7) {\n                a = (a * ONE_20) / a7;\n                sum += x7;\n            }\n\n            if (a >= a8) {\n                a = (a * ONE_20) / a8;\n                sum += x8;\n            }\n\n            if (a >= a9) {\n                a = (a * ONE_20) / a9;\n                sum += x9;\n            }\n\n            if (a >= a10) {\n                a = (a * ONE_20) / a10;\n                sum += x10;\n            }\n\n            if (a >= a11) {\n                a = (a * ONE_20) / a11;\n                sum += x11;\n            }\n\n            // a is now a small number (smaller than a_11, which roughly equals 1.06). This means we can use a Taylor series\n            // that converges rapidly for values of `a` close to one - the same one used in ln_36.\n            // Let z = (a - 1) / (a + 1).\n            // ln(a) = 2 * (z + z^3 / 3 + z^5 / 5 + z^7 / 7 + ... + z^(2 * n + 1) / (2 * n + 1))\n\n            // Recall that 20 digit fixed point division requires multiplying by ONE_20, and multiplication requires\n            // division by ONE_20.\n            int256 z = ((a - ONE_20) * ONE_20) / (a + ONE_20);\n            int256 z_squared = (z * z) / ONE_20;\n\n            // num is the numerator of the series: the z^(2 * n + 1) term\n            int256 num = z;\n\n            // seriesSum holds the accumulated sum of each term in the series, starting with the initial z\n            int256 seriesSum = num;\n\n            // In each step, the numerator is multiplied by z^2\n            num = (num * z_squared) / ONE_20;\n            seriesSum += num / 3;\n\n            num = (num * z_squared) / ONE_20;\n            seriesSum += num / 5;\n\n            num = (num * z_squared) / ONE_20;\n            seriesSum += num / 7;\n\n            num = (num * z_squared) / ONE_20;\n            seriesSum += num / 9;\n\n            num = (num * z_squared) / ONE_20;\n            seriesSum += num / 11;\n\n            // 6 Taylor terms are sufficient for 36 decimal precision.\n\n            // Finally, we multiply by 2 (non fixed point) to compute ln(remainder)\n            seriesSum *= 2;\n\n            // We now have the sum of all x_n present, and the Taylor approximation of the logarithm of the remainder (both\n            // with 20 decimals). All that remains is to sum these two, and then drop two digits to return a 18 decimal\n            // value.\n\n            return (sum + seriesSum) / 100;\n        }\n    }\n\n    /**\n     * @dev Intrnal high precision (36 decimal places) natural logarithm (ln(x)) with signed 18 decimal fixed point argument,\n     * for x close to one.\n     *\n     * Should only be used if x is between LN_36_LOWER_BOUND and LN_36_UPPER_BOUND.\n     */\n    function _ln_36(int256 x) private pure returns (int256) {\n        unchecked {\n            // Since ln(1) = 0, a value of x close to one will yield a very small result, which makes using 36 digits\n            // worthwhile.\n\n            // First, we transform x to a 36 digit fixed point value.\n            x *= ONE_18;\n\n            // We will use the following Taylor expansion, which converges very rapidly. Let z = (x - 1) / (x + 1).\n            // ln(x) = 2 * (z + z^3 / 3 + z^5 / 5 + z^7 / 7 + ... + z^(2 * n + 1) / (2 * n + 1))\n\n            // Recall that 36 digit fixed point division requires multiplying by ONE_36, and multiplication requires\n            // division by ONE_36.\n            int256 z = ((x - ONE_36) * ONE_36) / (x + ONE_36);\n            int256 z_squared = (z * z) / ONE_36;\n\n            // num is the numerator of the series: the z^(2 * n + 1) term\n            int256 num = z;\n\n            // seriesSum holds the accumulated sum of each term in the series, starting with the initial z\n            int256 seriesSum = num;\n\n            // In each step, the numerator is multiplied by z^2\n            num = (num * z_squared) / ONE_36;\n            seriesSum += num / 3;\n\n            num = (num * z_squared) / ONE_36;\n            seriesSum += num / 5;\n\n            num = (num * z_squared) / ONE_36;\n            seriesSum += num / 7;\n\n            num = (num * z_squared) / ONE_36;\n            seriesSum += num / 9;\n\n            num = (num * z_squared) / ONE_36;\n            seriesSum += num / 11;\n\n            num = (num * z_squared) / ONE_36;\n            seriesSum += num / 13;\n\n            num = (num * z_squared) / ONE_36;\n            seriesSum += num / 15;\n\n            // 8 Taylor terms are sufficient for 36 decimal precision.\n\n            // All that remains is multiplying by 2 (non fixed point).\n            return seriesSum * 2;\n        }\n    }\n}\n"},{"file_path":"contracts/core/libraries/math/PMath.sol","source_code":"// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program.  If not, see <http://www.gnu.org/licenses/>.\n\npragma solidity ^0.8.0;\n\n/* solhint-disable private-vars-leading-underscore, reason-string */\n\nlibrary PMath {\n    uint256 internal constant ONE = 1e18; // 18 decimal places\n    int256 internal constant IONE = 1e18; // 18 decimal places\n\n    function subMax0(uint256 a, uint256 b) internal pure returns (uint256) {\n        unchecked {\n            return (a >= b ? a - b : 0);\n        }\n    }\n\n    function subNoNeg(int256 a, int256 b) internal pure returns (int256) {\n        require(a >= b, \"negative\");\n        return a - b; // no unchecked since if b is very negative, a - b might overflow\n    }\n\n    function mulDown(uint256 a, uint256 b) internal pure returns (uint256) {\n        uint256 product = a * b;\n        unchecked {\n            return product / ONE;\n        }\n    }\n\n    function mulDown(int256 a, int256 b) internal pure returns (int256) {\n        int256 product = a * b;\n        unchecked {\n            return product / IONE;\n        }\n    }\n\n    function divDown(uint256 a, uint256 b) internal pure returns (uint256) {\n        uint256 aInflated = a * ONE;\n        unchecked {\n            return aInflated / b;\n        }\n    }\n\n    function divDown(int256 a, int256 b) internal pure returns (int256) {\n        int256 aInflated = a * IONE;\n        unchecked {\n            return aInflated / b;\n        }\n    }\n\n    function rawDivUp(uint256 a, uint256 b) internal pure returns (uint256) {\n        return (a + b - 1) / b;\n    }\n\n    function rawDivUp(int256 a, int256 b) internal pure returns (int256) {\n        return (a + b - 1) / b;\n    }\n\n    function tweakUp(uint256 a, uint256 factor) internal pure returns (uint256) {\n        return mulDown(a, ONE + factor);\n    }\n\n    function tweakDown(uint256 a, uint256 factor) internal pure returns (uint256) {\n        return mulDown(a, ONE - factor);\n    }\n\n    /// @return res = min(a + b, bound)\n    /// @dev This function should handle arithmetic operation and bound check without overflow/underflow\n    function addWithUpperBound(uint256 a, uint256 b, uint256 bound) internal pure returns (uint256 res) {\n        unchecked {\n            if (type(uint256).max - b < a) res = bound;\n            else res = min(bound, a + b);\n        }\n    }\n\n    /// @return res = max(a - b, bound)\n    /// @dev This function should handle arithmetic operation and bound check without overflow/underflow\n    function subWithLowerBound(uint256 a, uint256 b, uint256 bound) internal pure returns (uint256 res) {\n        unchecked {\n            if (b > a) res = bound;\n            else res = max(a - b, bound);\n        }\n    }\n\n    function clamp(uint256 x, uint256 lower, uint256 upper) internal pure returns (uint256 res) {\n        res = x;\n        if (x < lower) res = lower;\n        else if (x > upper) res = upper;\n    }\n\n    // @author Uniswap\n    function sqrt(uint256 y) internal pure returns (uint256 z) {\n        if (y > 3) {\n            z = y;\n            uint256 x = y / 2 + 1;\n            while (x < z) {\n                z = x;\n                x = (y / x + x) / 2;\n            }\n        } else if (y != 0) {\n            z = 1;\n        }\n    }\n\n    function square(uint256 x) internal pure returns (uint256) {\n        return x * x;\n    }\n\n    function squareDown(uint256 x) internal pure returns (uint256) {\n        return mulDown(x, x);\n    }\n\n    function abs(int256 x) internal pure returns (uint256) {\n        return uint256(x > 0 ? x : -x);\n    }\n\n    function neg(int256 x) internal pure returns (int256) {\n        return x * (-1);\n    }\n\n    function neg(uint256 x) internal pure returns (int256) {\n        return Int(x) * (-1);\n    }\n\n    function max(uint256 x, uint256 y) internal pure returns (uint256) {\n        return (x > y ? x : y);\n    }\n\n    function max(int256 x, int256 y) internal pure returns (int256) {\n        return (x > y ? x : y);\n    }\n\n    function min(uint256 x, uint256 y) internal pure returns (uint256) {\n        return (x < y ? x : y);\n    }\n\n    function min(int256 x, int256 y) internal pure returns (int256) {\n        return (x < y ? x : y);\n    }\n\n    /*///////////////////////////////////////////////////////////////\n                               SIGNED CASTS\n    //////////////////////////////////////////////////////////////*/\n\n    function Int(uint256 x) internal pure returns (int256) {\n        require(x <= uint256(type(int256).max));\n        return int256(x);\n    }\n\n    function Int128(int256 x) internal pure returns (int128) {\n        require(type(int128).min <= x && x <= type(int128).max);\n        return int128(x);\n    }\n\n    function Int128(uint256 x) internal pure returns (int128) {\n        return Int128(Int(x));\n    }\n\n    /*///////////////////////////////////////////////////////////////\n                               UNSIGNED CASTS\n    //////////////////////////////////////////////////////////////*/\n\n    function Uint(int256 x) internal pure returns (uint256) {\n        require(x >= 0);\n        return uint256(x);\n    }\n\n    function Uint32(uint256 x) internal pure returns (uint32) {\n        require(x <= type(uint32).max);\n        return uint32(x);\n    }\n\n    function Uint64(uint256 x) internal pure returns (uint64) {\n        require(x <= type(uint64).max);\n        return uint64(x);\n    }\n\n    function Uint112(uint256 x) internal pure returns (uint112) {\n        require(x <= type(uint112).max);\n        return uint112(x);\n    }\n\n    function Uint96(uint256 x) internal pure returns (uint96) {\n        require(x <= type(uint96).max);\n        return uint96(x);\n    }\n\n    function Uint128(uint256 x) internal pure returns (uint128) {\n        require(x <= type(uint128).max);\n        return uint128(x);\n    }\n\n    function Uint192(uint256 x) internal pure returns (uint192) {\n        require(x <= type(uint192).max);\n        return uint192(x);\n    }\n\n    function Uint80(uint256 x) internal pure returns (uint80) {\n        require(x <= type(uint80).max);\n        return uint80(x);\n    }\n\n    function isAApproxB(uint256 a, uint256 b, uint256 eps) internal pure returns (bool) {\n        return mulDown(b, ONE - eps) <= a && a <= mulDown(b, ONE + eps);\n    }\n\n    function isAGreaterApproxB(uint256 a, uint256 b, uint256 eps) internal pure returns (bool) {\n        return a >= b && a <= mulDown(b, ONE + eps);\n    }\n\n    function isASmallerApproxB(uint256 a, uint256 b, uint256 eps) internal pure returns (bool) {\n        return a <= b && a >= mulDown(b, ONE - eps);\n    }\n}\n"},{"file_path":"contracts/interfaces/IPChainlinkOracle.sol","source_code":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nimport \"@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol\";\n\nenum PendleOracleType {\n    PT_TO_SY,\n    PT_TO_ASSET,\n    LP_TO_SY,\n    LP_TO_ASSET\n}\n\ninterface IPChainlinkOracle is AggregatorV3Interface {}\n"},{"file_path":"contracts/interfaces/IPGauge.sol","source_code":"// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity ^0.8.0;\n\ninterface IPGauge {\n    function totalActiveSupply() external view returns (uint256);\n\n    function activeBalance(address user) external view returns (uint256);\n\n    // only available for newer factories. please check the verified contracts\n    event RedeemRewards(address indexed user, uint256[] rewardsOut);\n}\n"},{"file_path":"contracts/interfaces/IPInterestManagerYT.sol","source_code":"// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity ^0.8.0;\n\ninterface IPInterestManagerYT {\n    event CollectInterestFee(uint256 amountInterestFee);\n\n    function userInterest(address user) external view returns (uint128 lastPYIndex, uint128 accruedInterest);\n}\n"},{"file_path":"contracts/interfaces/IPMarket.sol","source_code":"// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity ^0.8.0;\n\nimport \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\nimport \"./IPPrincipalToken.sol\";\nimport \"./IPYieldToken.sol\";\nimport \"./IStandardizedYield.sol\";\nimport \"./IPGauge.sol\";\nimport \"../core/Market/MarketMathCore.sol\";\n\ninterface IPMarket is IERC20Metadata, IPGauge {\n    event Mint(address indexed receiver, uint256 netLpMinted, uint256 netSyUsed, uint256 netPtUsed);\n\n    event Burn(\n        address indexed receiverSy,\n        address indexed receiverPt,\n        uint256 netLpBurned,\n        uint256 netSyOut,\n        uint256 netPtOut\n    );\n\n    event Swap(\n        address indexed caller,\n        address indexed receiver,\n        int256 netPtOut,\n        int256 netSyOut,\n        uint256 netSyFee,\n        uint256 netSyToReserve\n    );\n\n    event UpdateImpliedRate(uint256 indexed timestamp, uint256 lnLastImpliedRate);\n\n    event IncreaseObservationCardinalityNext(\n        uint16 observationCardinalityNextOld,\n        uint16 observationCardinalityNextNew\n    );\n\n    function mint(\n        address receiver,\n        uint256 netSyDesired,\n        uint256 netPtDesired\n    ) external returns (uint256 netLpOut, uint256 netSyUsed, uint256 netPtUsed);\n\n    function burn(\n        address receiverSy,\n        address receiverPt,\n        uint256 netLpToBurn\n    ) external returns (uint256 netSyOut, uint256 netPtOut);\n\n    function swapExactPtForSy(\n        address receiver,\n        uint256 exactPtIn,\n        bytes calldata data\n    ) external returns (uint256 netSyOut, uint256 netSyFee);\n\n    function swapSyForExactPt(\n        address receiver,\n        uint256 exactPtOut,\n        bytes calldata data\n    ) external returns (uint256 netSyIn, uint256 netSyFee);\n\n    function redeemRewards(address user) external returns (uint256[] memory);\n\n    function readState(address router) external view returns (MarketState memory market);\n\n    function observe(uint32[] memory secondsAgos) external view returns (uint216[] memory lnImpliedRateCumulative);\n\n    function increaseObservationsCardinalityNext(uint16 cardinalityNext) external;\n\n    function readTokens() external view returns (IStandardizedYield _SY, IPPrincipalToken _PT, IPYieldToken _YT);\n\n    function getRewardTokens() external view returns (address[] memory);\n\n    function isExpired() external view returns (bool);\n\n    function expiry() external view returns (uint256);\n\n    function observations(\n        uint256 index\n    ) external view returns (uint32 blockTimestamp, uint216 lnImpliedRateCumulative, bool initialized);\n\n    function _storage()\n        external\n        view\n        returns (\n            int128 totalPt,\n            int128 totalSy,\n            uint96 lastLnImpliedRate,\n            uint16 observationIndex,\n            uint16 observationCardinality,\n            uint16 observationCardinalityNext\n        );\n}\n"},{"file_path":"contracts/oracles/PtYtLpOracle/PendleLpOracleLib.sol","source_code":"// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity ^0.8.0;\n\nimport \"./PendlePYOracleLib.sol\";\n\nlibrary PendleLpOracleLib {\n    using PendlePYOracleLib for IPMarket;\n    using PMath for uint256;\n    using PMath for int256;\n    using MarketMathCore for MarketState;\n\n    /**\n      * This function returns the approximated twap rate LP/asset on market, but take into account the current rate of SY\n     This is to account for special cases where underlying asset becomes insolvent and has decreasing exchangeRate\n     * @param market market to get rate from\n     * @param duration twap duration\n     */\n    function getLpToAssetRate(IPMarket market, uint32 duration) internal view returns (uint256) {\n        (uint256 syIndex, uint256 pyIndex) = market.getSYandPYIndexCurrent();\n        uint256 lpToAssetRateRaw = _getLpToAssetRateRaw(market, duration, pyIndex);\n        if (syIndex >= pyIndex) {\n            return lpToAssetRateRaw;\n        } else {\n            return (lpToAssetRateRaw * syIndex) / pyIndex;\n        }\n    }\n\n    /**\n      * This function returns the approximated twap rate LP/asset on market, but take into account the current rate of SY\n     This is to account for special cases where underlying asset becomes insolvent and has decreasing exchangeRate\n     * @param market market to get rate from\n     * @param duration twap duration\n     */\n    function getLpToSyRate(IPMarket market, uint32 duration) internal view returns (uint256) {\n        (uint256 syIndex, uint256 pyIndex) = market.getSYandPYIndexCurrent();\n        uint256 lpToAssetRateRaw = _getLpToAssetRateRaw(market, duration, pyIndex);\n        if (syIndex >= pyIndex) {\n            return lpToAssetRateRaw.divDown(syIndex);\n        } else {\n            return lpToAssetRateRaw.divDown(pyIndex);\n        }\n    }\n\n    function _getLpToAssetRateRaw(\n        IPMarket market,\n        uint32 duration,\n        uint256 pyIndex\n    ) private view returns (uint256 lpToAssetRateRaw) {\n        MarketState memory state = market.readState(address(0));\n\n        int256 totalHypotheticalAsset;\n        if (state.expiry <= block.timestamp) {\n            // 1 PT = 1 Asset post-expiry\n            totalHypotheticalAsset = state.totalPt + PYIndexLib.syToAsset(PYIndex.wrap(pyIndex), state.totalSy);\n        } else {\n            MarketPreCompute memory comp = state.getMarketPreCompute(PYIndex.wrap(pyIndex), block.timestamp);\n\n            (int256 rateOracle, int256 rateHypTrade) = _getPtRatesRaw(market, state, duration);\n            int256 cParam = LogExpMath.exp(comp.rateScalar.mulDown((rateOracle - comp.rateAnchor)));\n\n            int256 tradeSize = (cParam.mulDown(comp.totalAsset) - state.totalPt).divDown(\n                PMath.IONE + cParam.divDown(rateHypTrade)\n            );\n\n            totalHypotheticalAsset =\n                comp.totalAsset -\n                tradeSize.divDown(rateHypTrade) +\n                (state.totalPt + tradeSize).divDown(rateOracle);\n        }\n\n        lpToAssetRateRaw = totalHypotheticalAsset.divDown(state.totalLp).Uint();\n    }\n\n    function _getPtRatesRaw(\n        IPMarket market,\n        MarketState memory state,\n        uint32 duration\n    ) private view returns (int256 rateOracle, int256 rateHypTrade) {\n        uint256 lnImpliedRate = market.getMarketLnImpliedRate(duration);\n        uint256 timeToExpiry = state.expiry - block.timestamp;\n        rateOracle = MarketMathCore._getExchangeRateFromImpliedRate(lnImpliedRate, timeToExpiry);\n\n        int256 rateLastTrade = MarketMathCore._getExchangeRateFromImpliedRate(state.lastLnImpliedRate, timeToExpiry);\n        rateHypTrade = (rateLastTrade + rateOracle) / 2;\n    }\n}\n"},{"file_path":"contracts/oracles/PtYtLpOracle/PendlePYOracleLib.sol","source_code":"// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity ^0.8.0;\n\nimport \"../../interfaces/IPMarket.sol\";\nimport \"../../core/libraries/math/PMath.sol\";\n\n// This library can & should be integrated directly for optimal gas usage.\n// If you prefer not to integrate it directly, the PendlePtOracle contract (a pre-deployed version of this contract) can be used.\nlibrary PendlePYOracleLib {\n    using PMath for uint256;\n    using PMath for int256;\n\n    /**\n     * This function returns the twap rate PT/Asset on market, but take into account the current rate of SY\n     This is to account for special cases where underlying asset becomes insolvent and has decreasing exchangeRate\n     * @param market market to get rate from\n     * @param duration twap duration\n     */\n    function getPtToAssetRate(IPMarket market, uint32 duration) internal view returns (uint256) {\n        (uint256 syIndex, uint256 pyIndex) = getSYandPYIndexCurrent(market);\n        if (syIndex >= pyIndex) {\n            return getPtToAssetRateRaw(market, duration);\n        } else {\n            return (getPtToAssetRateRaw(market, duration) * syIndex) / pyIndex;\n        }\n    }\n\n    /**\n     * This function returns the twap rate YT/Asset on market, but take into account the current rate of SY\n     This is to account for special cases where underlying asset becomes insolvent and has decreasing exchangeRate\n     * @param market market to get rate from\n     * @param duration twap duration\n     */\n    function getYtToAssetRate(IPMarket market, uint32 duration) internal view returns (uint256) {\n        (uint256 syIndex, uint256 pyIndex) = getSYandPYIndexCurrent(market);\n        if (syIndex >= pyIndex) {\n            return getYtToAssetRateRaw(market, duration);\n        } else {\n            return (getYtToAssetRateRaw(market, duration) * syIndex) / pyIndex;\n        }\n    }\n\n    /// @notice Similar to getPtToAsset but returns the rate in SY instead\n    function getPtToSyRate(IPMarket market, uint32 duration) internal view returns (uint256) {\n        (uint256 syIndex, uint256 pyIndex) = getSYandPYIndexCurrent(market);\n        if (syIndex >= pyIndex) {\n            return getPtToAssetRateRaw(market, duration).divDown(syIndex);\n        } else {\n            return getPtToAssetRateRaw(market, duration).divDown(pyIndex);\n        }\n    }\n\n    /// @notice Similar to getPtToAsset but returns the rate in SY instead\n    function getYtToSyRate(IPMarket market, uint32 duration) internal view returns (uint256) {\n        (uint256 syIndex, uint256 pyIndex) = getSYandPYIndexCurrent(market);\n        if (syIndex >= pyIndex) {\n            return getYtToAssetRateRaw(market, duration).divDown(syIndex);\n        } else {\n            return getYtToAssetRateRaw(market, duration).divDown(pyIndex);\n        }\n    }\n\n    /// @notice returns the raw rate without taking into account whether SY is solvent\n    function getPtToAssetRateRaw(IPMarket market, uint32 duration) internal view returns (uint256) {\n        uint256 expiry = market.expiry();\n\n        if (expiry <= block.timestamp) {\n            return PMath.ONE;\n        } else {\n            uint256 lnImpliedRate = getMarketLnImpliedRate(market, duration);\n            uint256 timeToExpiry = expiry - block.timestamp;\n            uint256 assetToPtRate = MarketMathCore._getExchangeRateFromImpliedRate(lnImpliedRate, timeToExpiry).Uint();\n            return PMath.ONE.divDown(assetToPtRate);\n        }\n    }\n\n    /// @notice returns the raw rate without taking into account whether SY is solvent\n    function getYtToAssetRateRaw(IPMarket market, uint32 duration) internal view returns (uint256) {\n        return PMath.ONE - getPtToAssetRateRaw(market, duration);\n    }\n\n    function getSYandPYIndexCurrent(IPMarket market) internal view returns (uint256 syIndex, uint256 pyIndex) {\n        (IStandardizedYield SY, , IPYieldToken YT) = market.readTokens();\n\n        syIndex = SY.exchangeRate();\n        uint256 pyIndexStored = YT.pyIndexStored();\n\n        if (YT.doCacheIndexSameBlock() && YT.pyIndexLastUpdatedBlock() == block.number) {\n            pyIndex = pyIndexStored;\n        } else {\n            pyIndex = PMath.max(syIndex, pyIndexStored);\n        }\n    }\n\n    function getMarketLnImpliedRate(IPMarket market, uint32 duration) internal view returns (uint256) {\n        if (duration == 0) {\n            (,,uint96 lnImpliedRate,,,) = IPMarket(market)._storage();\n            return uint256(lnImpliedRate);\n        }\n\n        uint32[] memory durations = new uint32[](2);\n        durations[0] = duration;\n\n        uint216[] memory lnImpliedRateCumulative = market.observe(durations);\n        return (lnImpliedRateCumulative[1] - lnImpliedRateCumulative[0]) / duration;\n    }\n}\n"}],"is_verified_via_sourcify":false,"can_be_visualized_via_sol2uml":true,"evm_version":"shanghai","language":"solidity","is_verified_via_eth_bytecode_db":false,"is_fully_verified":false,"license_type":"none","is_blueprint":false,"name":"PendleChainlinkOracle","creation_bytecode":"0x610160806040523462000116576060816200255a80380380916200002482856200011a565b83398101031262000116576200003a8162000152565b9060208101519063ffffffff821682036200011657604001516004811015620001165760ff6200008c620000846200009493868496336080528160a05260c0528160e05262000199565b941662000167565b921662000167565b610120908152610100918252620000aa620003d9565b610140908152604051916120f3938462000467853960805184610196015260a05184818161028001526111d3015260c0518481816104d901526111f5015260e0518461052d015251838181610443015261129301525182818161012901526112ba015251816112160152f35b5f80fd5b601f909101601f19168101906001600160401b038211908210176200013e57604052565b634e487b7160e01b5f52604160045260245ffd5b51906001600160a01b03821682036200011657565b604d81116200017657600a0a90565b634e487b7160e01b5f52601160045260245ffd5b519060ff821682036200011657565b60408051630b2339af60e21b81526060949392600492916001600160a01b0391879082908690829086165afa9081156200032e575f9162000380575b50825163313ce56760e01b81529491166020858581845afa9485156200032e579087915f9662000338575b508351630a40bee560e41b815291908290869082905afa9687156200032e575f97620002d2575b505082811015620002bf57600181036200024357505050508190565b9294928062000253575050509190565b9294926003810362000269575050505060129190565b92945090916002036200027e57505060129190565b620002bb92505191829162461bcd60e51b8352820160609060208152600d60208201526c1b9bdd081cdd5c1c1bdc9d1959609a1b60408201520190565b0390fd5b602183634e487b7160e01b5f525260245ffd5b9080929750813d831162000326575b620002ed81836200011a565b810103126200011657600281511015620001165781816200031560206200031d940162000152565b50016200018a565b945f8062000227565b503d620002e1565b83513d5f823e3d90fd5b915094506020813d60201162000377575b8162000358602093836200011a565b810103126200011657866200036e85926200018a565b95909162000200565b3d915062000349565b90508681813d8311620003d1575b6200039a81836200011a565b8101031262000116578051908282168203620001165760208101518381160362000116578301518281160362000116575f620001d5565b503d6200038e565b60e0516004811015620004525780620003f25750600490565b60018103620004015750600390565b60028103620004105750600290565b6003036200041d57600190565b60405162461bcd60e51b815260206004820152600d60248201526c1b9bdd081cdd5c1c1bdc9d1959609a1b6044820152606490fd5b634e487b7160e01b5f52602160045260245ffdfe6080604090808252600480361015610015575f80fd5b5f3560e01c9182630aa33a24146104fd5750816326d895451461049f578163313ce567146104665781634ae5fa9b1461040e57816354fd4d50146103d55781637284e416146102a457816380f55605146102365781639a6fc8f5146101ba57508063c45a01551461014c578063ee81d997146100f45763feaf968c14610099575f80fd5b346100f0575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f05760a0905f6100d36111bc565b9180519282845260208401528201524260608201525f6080820152f35b5f80fd5b50346100f0575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f057602090517f00000000000000000000000000000000000000000000000000000000000000008152f35b50346100f0575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f0576020905173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000168152f35b82346100f05760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f057813569ffffffffffffffffffff81168091036100f0576102105760a0905f6100d36111bc565b517fbfbe031f000000000000000000000000000000000000000000000000000000008152fd5b82346100f0575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f0576020905173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000168152f35b82346100f0575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f057805191606083019083821067ffffffffffffffff8311176103a9575081526022825260207f50656e646c6520436861696e6c696e6b2d636f6d70617469626c65204f72616360208401527f6c65000000000000000000000000000000000000000000000000000000000000828401528151928391602083528151918260208501525f5b8381106103935750505f83830185015250601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0168101030190f35b8181018301518782018701528694508201610356565b6041907f4e487b71000000000000000000000000000000000000000000000000000000005f525260245ffd5b82346100f0575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f0576020905160018152f35b82346100f0575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f057602090517f00000000000000000000000000000000000000000000000000000000000000008152f35b82346100f0575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f0576020905160128152f35b82346100f0575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f0576020905163ffffffff7f0000000000000000000000000000000000000000000000000000000000000000168152f35b346100f0575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f0577f00000000000000000000000000000000000000000000000000000000000000008281101561055c57602092508152f35b6021837f4e487b71000000000000000000000000000000000000000000000000000000005f525260245ffd5b90670de0b6b3a7640000918281029281840414901517156105a557565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b818102929181159184041417156105a557565b81156105ef570490565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b9061063261062983610762565b92839194610a89565b9181811061063f57505090565b61064c90610651936105d2565b6105e5565b90565b61066961066082610762565b93849193610a89565b9180821061067e575061064c61065192610588565b905061064c61065192610588565b9061069682610762565b908181106106a9575050610651916110a0565b6106ba61064c9293610651956110a0565b6105d2565b6106c881610762565b9091908083106106e55750610651926106e0916110a0565b61106f565b9150610651926106e0916110a0565b90601f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0910116810190811067ffffffffffffffff82111761073557604052565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b9073ffffffffffffffffffffffffffffffffffffffff80606060409460048651809481937f2c8ce6bc000000000000000000000000000000000000000000000000000000008352165afa938415610948575f915f956109fb575b50828151927f3ba0b9a9000000000000000000000000000000000000000000000000000000008452836004816020978894165afa9283156109c2575f936109cc575b50829516908051937fd2a3584e0000000000000000000000000000000000000000000000000000000085528085600481865afa9485156109c2575f95610993575b508151927f516399df0000000000000000000000000000000000000000000000000000000084528184600481845afa938415610989575f94610951575b50836108a2575b5050505f14610890575090565b908082111561089d575090565b905090565b829350819060049351938480927f60e0a9e10000000000000000000000000000000000000000000000000000000082525afa92831561094857505f92610901575b50506fffffffffffffffffffffffffffffffff1643145f8080610883565b90809250813d8311610941575b61091881836106f4565b810103126100f057516fffffffffffffffffffffffffffffffff811681036100f0575f806108e3565b503d61090e565b513d5f823e3d90fd5b9093508181813d8311610982575b61096981836106f4565b810103126100f0575180151581036100f057925f61087c565b503d61095f565b83513d5f823e3d90fd5b9080955081813d83116109bb575b6109ab81836106f4565b810103126100f05751935f61083f565b503d6109a1565b82513d5f823e3d90fd5b9092508381813d83116109f4575b6109e481836106f4565b810103126100f05751915f6107fe565b503d6109da565b915093506060813d606011610a4e575b81610a18606093836106f4565b810103126100f05780519082821682036100f0576020810151838116036100f0578401519082821682036100f05790935f6107bc565b3d9150610a0b565b81810392915f1380158285131691841216176105a557565b9190915f83820193841291129080158216911516176105a557565b909173ffffffffffffffffffffffffffffffffffffffff9260409283517f794052f30000000000000000000000000000000000000000000000000000000081526004905f82820152610120602491818184818c89165afa988915611065575f99610f92575b50505060a0870180519093904210610b415750505050508291610b28610b3292610b22610b379651916020870151906117ff565b90610a6e565b925b015191611341565b6113b6565b5f81126100f05790565b86519495936080860167ffffffffffffffff811187821017610f675788525f865260208601965f8852888701925f84525f60608901524283511115610f3f57610b8b428451611093565b9660808c01516301e1338090818102918183051490151715610ee9577f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff89116100f0578815610f14577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff89147f8000000000000000000000000000000000000000000000000000000000000000821416610ee9578890055f811315610ebb57895260208c0151610c3a916117ff565b808a528b5180158015610eb3575b610e7f5750508a51966101008c0151978a5198610c67838c5192611bf3565b91670de0b6b3a76400009a8b8412610e505790610b32610c8a610c909383610a6e565b91611341565b8a8114610e2857808b03905f81128c83128116908d841390151617610dfd578f90610d5a98610d346101009f9e9d9c9b978f8f9b610d549b610d24926060610d1c610d2d968f610d4e9f60029f90610d439f610d1092610d3e9f610d05610d00610d0a94610b32610b3294611341565b611c33565b611341565b90610a56565b905260c08c0151611bf3565b910152611911565b92429051611093565b8092611bf3565b9e8f930151611bf3565b610a6e565b05985191518a610a56565b9061135e565b05611425565b91610d8085610b32610d7a87610d718c518961135e565b058d5190610a56565b95611341565b809401938412600116610dd3575050610b37969593610b32610d05610dc5610dcd96610d0a610db9610b329b98610b32610b2299611341565b975191610b3289611341565b948951610a6e565b92610b2a565b6011907f4e487b71000000000000000000000000000000000000000000000000000000005f52525ffd5b8960118c7f4e487b71000000000000000000000000000000000000000000000000000000005f52525ffd5b898e517fa9c8b14d000000000000000000000000000000000000000000000000000000008152fd5b898f858d9151917fca78c8a4000000000000000000000000000000000000000000000000000000008352820152fd5b6044918789928e51937fb1c4aefb000000000000000000000000000000000000000000000000000000008552840152820152fd5b508115610c48565b8787918d51917f1ca41876000000000000000000000000000000000000000000000000000000008352820152fd5b866011897f4e487b71000000000000000000000000000000000000000000000000000000005f52525ffd5b866012897f4e487b71000000000000000000000000000000000000000000000000000000005f52525ffd5b858a517fb2094b59000000000000000000000000000000000000000000000000000000008152fd5b836041867f4e487b71000000000000000000000000000000000000000000000000000000005f52525ffd5b90918093995082813d831161105e575b610fac81836106f4565b810103126100f057875192830183811067ffffffffffffffff82111761103357885281518352602082015160208401528782015188840152606082015190811681036100f05760608301526080810151608083015260a081015160a083015260c081015160c083015260e081015160e08301526101008091015190820152955f8080610aee565b896041867f4e487b71000000000000000000000000000000000000000000000000000000005f52525ffd5b503d610fa2565b88513d5f823e3d90fd5b90670de0b6b3a7640000918281029281840414901517156105a557610651916105e5565b919082039182116105a557565b6040517fe184c9be00000000000000000000000000000000000000000000000000000000815260208160048173ffffffffffffffffffffffffffffffffffffffff86165afa9081156111b1575f9161117f575b5042811161110a57505050670de0b6b3a764000090565b61112761111f6301e133809461112d94611911565b914290611093565b906105d2565b047f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81116100f05761115e90611425565b5f81126100f05780156105ef576ec097ce7bc90715b34b9f10000000000490565b90506020813d6020116111a9575b8161119a602093836106f4565b810103126100f057515f6110f3565b3d915061118d565b6040513d5f823e3d90fd5b73ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000167f00000000000000000000000000000000000000000000000000000000000000007f000000000000000000000000000000000000000000000000000000000000000080600114611330578060021461131f578060031461130957600414611281577f4e487b71000000000000000000000000000000000000000000000000000000005f52605160045260245ffd5b6112916112b8916112df936106bf565b7f0000000000000000000000000000000000000000000000000000000000000000906105d2565b7f0000000000000000000000000000000000000000000000000000000000000000906105e5565b7f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81116100f05790565b5061131a6112b8916112df9361068c565b611291565b5061131a6112b8916112df93610654565b5061131a6112b8916112df9361061c565b90670de0b6b3a7640000918281029281840514901517156105a557565b81810292915f82127f80000000000000000000000000000000000000000000000000000000000000008214166105a55781840514901517156105a557565b80156105ef576ec097ce7bc90715b34b9f10000000000590565b81156105ef570590565b156113c757565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601060248201527f496e76616c6964206578706f6e656e74000000000000000000000000000000006044820152fd5b7ffffffffffffffffffffffffffffffffffffffffffffffffdc702bd3a30fc0000811215806117ec575b611458906113c0565b5f81126117d8576064906806f05b59d3b20000008112611775577ffffffffffffffffffffffffffffffffffffffffffffffff90fa4a62c4e0000000168056bc75e2d6310000082770195e54c5dd42177f53a27172fa9ec630262827000000000925b02819068ad78ebc5ac6200000081121561173c575b6856bc75e2d631000000811215611702575b682b5e3af16b188000008112156116ca575b6815af1d78b58c400000811215611692575b680ad78ebc5ac620000081121561165b575b82811215611624575b6802b5e3af16b18800008112156115ed575b68015af1d78b58c400008112156115b6575b60028382800205056003848383020505600485848302050585600581868402050560068287830205056007838883020505906008848984020505926009858a8602050595600a868b8902050597600b878c8b02050599600c888d8d0205059b0101010101010101010101010205020590565b6806f5f17757889379377ffffffffffffffffffffffffffffffffffffffffffffffffea50e2874a73c000084920192020590611544565b6808f00f760a4b2db55d7ffffffffffffffffffffffffffffffffffffffffffffffffd4a1c50e94e78000084920192020590611532565b680ebc5fb417461211107ffffffffffffffffffffffffffffffffffffffffffffffffa9438a1d29cf0000084920192020590611520565b68280e60114edb805d037ffffffffffffffffffffffffffffffffffffffffffffffff5287143a539e0000084920192020590611517565b690127fa27722cc06cc5e27fffffffffffffffffffffffffffffffffffffffffffffffea50e2874a73c0000084920192020590611505565b693f1fce3da636ea5cf8507fffffffffffffffffffffffffffffffffffffffffffffffd4a1c50e94e7800000849201920205906114f3565b6b02df0ab5a80a22c61ab5a7007fffffffffffffffffffffffffffffffffffffffffffffffa9438a1d29cf000000849201920205906114e1565b6e01855144814a7ff805980ff008400091507fffffffffffffffffffffffffffffffffffffffffffffff5287143a539e000000016114cf565b6803782dace9d900000081126117c5577ffffffffffffffffffffffffffffffffffffffffffffffffc87d25316270000000168056bc75e2d63100000826b1425982cf597cd205cef7380926114ba565b68056bc75e2d63100000826001926114ba565b6117e3905f03611425565b6106519061139c565b5068070c1cc73b00c8000081131561144f565b5f8212156118b2577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff915b5f81131561187657670de0b6b3a764000091611845916105d2565b047f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81116100f0576106519161135e565b7f800000000000000000000000000000000000000000000000000000000000000081146105a557670de0b6b3a764000091611845915f036105d2565b60019161182a565b519081600f0b82036100f057565b519061ffff821682036100f057565b8051156118e45760200190565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b9063ffffffff809116908115611af6576040928351606081019167ffffffffffffffff928281108482111761073557865260028252602091828101873682378661195a836118d7565b5287519586927f883bdbfd0000000000000000000000000000000000000000000000000000000084526024840190866004860152518091526044840192915f905b87838310611ad9575050505050918173ffffffffffffffffffffffffffffffffffffffff815f950392165afa928315611acf575f93611a22575b5050508051600110156118e457611a10927affffffffffffffffffffffffffffffffffffffffffffffffffffff9384809284015116926118d7565b511690038281116105a5578216041690565b909192503d805f833e611a3581836106f4565b81019082818303126100f0578051908482116100f0570181601f820112156100f0578051938411610735578360051b90865194611a74858401876106f4565b855283808601928201019283116100f0578301905b828210611a9c57505050505f80806119d5565b81517affffffffffffffffffffffffffffffffffffffffffffffffffffff811681036100f0578152908301908301611a89565b85513d5f823e3d90fd5b8451821686528a965094850194909301926001919091019061199b565b505060c073ffffffffffffffffffffffffffffffffffffffff916004604051809481937fc3fb90d6000000000000000000000000000000000000000000000000000000008352165afa80156111b1575f90611b5f575b6bffffffffffffffffffffffff91501690565b5060c0813d60c011611beb575b81611b7960c093836106f4565b810103126100f057611b8a816118ba565b50611b97602082016118ba565b5060408101516bffffffffffffffffffffffff811681036100f057611be560a083611bd160606bffffffffffffffffffffffff96016118c8565b50611bde608082016118c8565b50016118c8565b50611b4c565b3d9150611b6c565b6301e1338091611c02916105d2565b047f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81116100f05761065190611425565b5f811315611d155780670c7d713b49da00001280611d04575b15611cfb57670de0b6b3a7640000906ec097ce7bc90715b34b9f100000000090611c9f908302828101907fffffffffffffffffffffffffffffffffff3f68318436f8ea4cb460f0000000000183026113b6565b9080828002059181838202058284820205838582020591848684020593858786020595808888020597880205600f900596600d900595600b900594600990059360079005926005900591600390050101010101010160011b0590565b61065190611d73565b50670f43fc2c04ee00008112611c4c565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600d60248201527f6f7574206f6620626f756e6473000000000000000000000000000000000000006044820152fd5b670de0b6b3a764000081126120a7576064905f7e1600ef3172e58d2e933ec884fde10064c63b5372d805e203c000000000000082121561207c575b73011798004d755d3c8bc8e03204cf44619e00000082121561205b575b820290808302906e01855144814a7ff805980ff00840009081831215612038575b50506b02df0ab5a80a22c61ab5a70080821215612018575b50693f1fce3da636ea5cf85080821215611ff8575b50690127fa27722cc06cc5e280821215611fd8575b5068280e60114edb805d0380821215611fb8575b50680ebc5fb4174612111080821215611fa1575b506808f00f760a4b2db55d80821215611f81575b506806f5f177578893793780821215611f61575b506806248f33704b28660380821215611f42575b506805c548670b9510e7ac80821215611f23575b50611ee268056bc75e2d6310000091827ffffffffffffffffffffffffffffffffffffffffffffffffa9438a1d29cf000008183019201026113b6565b9080828002059181838202058284820205916003600560076009600b888a89020598808b8b02059a8b0205059805960594059205010101010160011b010590565b68056bc75e2d631000006756bc75e2d63100009202059101905f611ea6565b68056bc75e2d6310000067ad78ebc5ac6200009202059101905f611e92565b68056bc75e2d6310000068015af1d78b58c400009202059101905f611e7e565b68056bc75e2d631000006802b5e3af16b18800009202059101905f611e6a565b68056bc75e2d63100000809202059101905f611e56565b68056bc75e2d63100000680ad78ebc5ac62000009202059101905f611e42565b68056bc75e2d631000006815af1d78b58c4000009202059101905f611e2e565b68056bc75e2d63100000682b5e3af16b188000009202059101905f611e19565b68056bc75e2d631000006856bc75e2d6310000009202059101905f611e04565b68ad78ebc5ac62000000925069021e19e0c9bab240000002059101905f80611dec565b906b1425982cf597cd205cef73806803782dace9d900000091059101611dcb565b50770195e54c5dd42177f53a27172fa9ec63026282700000000090056806f05b59d3b2000000611dae565b6120b36120b89161139c565b611d73565b5f039056fea26469706673582212209ff8249c142f6e0885939c4c49a82698a874e81534c962938dd51150f70e839d64736f6c634300081800330000000000000000000000009eaaeda23177b7168c55a3a0f937f6791973344900000000000000000000000000000000000000000000000000000000000003840000000000000000000000000000000000000000000000000000000000000001","external_libraries":[],"proxy_type":null,"implementations":[],"verified_at":"2026-01-21T16:19:14.742351Z","is_verified_via_verifier_alliance":false,"compiler_version":"v0.8.24+commit.e11b9ed9","decoded_constructor_args":[["0x9EaAedA23177B7168c55a3A0F937f67919733449",{"internalType":"address","name":"_market","type":"address"}],["900",{"internalType":"uint32","name":"_twapDuration","type":"uint32"}],["1",{"internalType":"enum PendleOracleType","name":"_baseOracleType","type":"uint8"}]],"sourcify_repo_url":null,"optimization_runs":1000000,"compiler_settings":{"evmVersion":"shanghai","libraries":{},"optimizer":{"enabled":true,"runs":1000000},"outputSelection":{"*":{"":["*"],"*":["*"]}},"viaIR":true},"is_verified":true,"verified_twin_address_hash":null,"optimization_enabled":true,"deployed_bytecode":"0x6080604090808252600480361015610015575f80fd5b5f3560e01c9182630aa33a24146104fd5750816326d895451461049f578163313ce567146104665781634ae5fa9b1461040e57816354fd4d50146103d55781637284e416146102a457816380f55605146102365781639a6fc8f5146101ba57508063c45a01551461014c578063ee81d997146100f45763feaf968c14610099575f80fd5b346100f0575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f05760a0905f6100d36111bc565b9180519282845260208401528201524260608201525f6080820152f35b5f80fd5b50346100f0575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f057602090517f0000000000000000000000000000000000000000000000000de0b6b3a76400008152f35b50346100f0575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f0576020905173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000009e5129dcc15d39625617dcd7f0f44fb0bb957ffd168152f35b82346100f05760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f057813569ffffffffffffffffffff81168091036100f0576102105760a0905f6100d36111bc565b517fbfbe031f000000000000000000000000000000000000000000000000000000008152fd5b82346100f0575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f0576020905173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000009eaaeda23177b7168c55a3a0f937f67919733449168152f35b82346100f0575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f057805191606083019083821067ffffffffffffffff8311176103a9575081526022825260207f50656e646c6520436861696e6c696e6b2d636f6d70617469626c65204f72616360208401527f6c65000000000000000000000000000000000000000000000000000000000000828401528151928391602083528151918260208501525f5b8381106103935750505f83830185015250601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0168101030190f35b8181018301518782018701528694508201610356565b6041907f4e487b71000000000000000000000000000000000000000000000000000000005f525260245ffd5b82346100f0575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f0576020905160018152f35b82346100f0575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f057602090517f0000000000000000000000000000000000000000000000000de0b6b3a76400008152f35b82346100f0575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f0576020905160128152f35b82346100f0575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f0576020905163ffffffff7f0000000000000000000000000000000000000000000000000000000000000384168152f35b346100f0575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f0577f00000000000000000000000000000000000000000000000000000000000000018281101561055c57602092508152f35b6021837f4e487b71000000000000000000000000000000000000000000000000000000005f525260245ffd5b90670de0b6b3a7640000918281029281840414901517156105a557565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b818102929181159184041417156105a557565b81156105ef570490565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b9061063261062983610762565b92839194610a89565b9181811061063f57505090565b61064c90610651936105d2565b6105e5565b90565b61066961066082610762565b93849193610a89565b9180821061067e575061064c61065192610588565b905061064c61065192610588565b9061069682610762565b908181106106a9575050610651916110a0565b6106ba61064c9293610651956110a0565b6105d2565b6106c881610762565b9091908083106106e55750610651926106e0916110a0565b61106f565b9150610651926106e0916110a0565b90601f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0910116810190811067ffffffffffffffff82111761073557604052565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b9073ffffffffffffffffffffffffffffffffffffffff80606060409460048651809481937f2c8ce6bc000000000000000000000000000000000000000000000000000000008352165afa938415610948575f915f956109fb575b50828151927f3ba0b9a9000000000000000000000000000000000000000000000000000000008452836004816020978894165afa9283156109c2575f936109cc575b50829516908051937fd2a3584e0000000000000000000000000000000000000000000000000000000085528085600481865afa9485156109c2575f95610993575b508151927f516399df0000000000000000000000000000000000000000000000000000000084528184600481845afa938415610989575f94610951575b50836108a2575b5050505f14610890575090565b908082111561089d575090565b905090565b829350819060049351938480927f60e0a9e10000000000000000000000000000000000000000000000000000000082525afa92831561094857505f92610901575b50506fffffffffffffffffffffffffffffffff1643145f8080610883565b90809250813d8311610941575b61091881836106f4565b810103126100f057516fffffffffffffffffffffffffffffffff811681036100f0575f806108e3565b503d61090e565b513d5f823e3d90fd5b9093508181813d8311610982575b61096981836106f4565b810103126100f0575180151581036100f057925f61087c565b503d61095f565b83513d5f823e3d90fd5b9080955081813d83116109bb575b6109ab81836106f4565b810103126100f05751935f61083f565b503d6109a1565b82513d5f823e3d90fd5b9092508381813d83116109f4575b6109e481836106f4565b810103126100f05751915f6107fe565b503d6109da565b915093506060813d606011610a4e575b81610a18606093836106f4565b810103126100f05780519082821682036100f0576020810151838116036100f0578401519082821682036100f05790935f6107bc565b3d9150610a0b565b81810392915f1380158285131691841216176105a557565b9190915f83820193841291129080158216911516176105a557565b909173ffffffffffffffffffffffffffffffffffffffff9260409283517f794052f30000000000000000000000000000000000000000000000000000000081526004905f82820152610120602491818184818c89165afa988915611065575f99610f92575b50505060a0870180519093904210610b415750505050508291610b28610b3292610b22610b379651916020870151906117ff565b90610a6e565b925b015191611341565b6113b6565b5f81126100f05790565b86519495936080860167ffffffffffffffff811187821017610f675788525f865260208601965f8852888701925f84525f60608901524283511115610f3f57610b8b428451611093565b9660808c01516301e1338090818102918183051490151715610ee9577f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff89116100f0578815610f14577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff89147f8000000000000000000000000000000000000000000000000000000000000000821416610ee9578890055f811315610ebb57895260208c0151610c3a916117ff565b808a528b5180158015610eb3575b610e7f5750508a51966101008c0151978a5198610c67838c5192611bf3565b91670de0b6b3a76400009a8b8412610e505790610b32610c8a610c909383610a6e565b91611341565b8a8114610e2857808b03905f81128c83128116908d841390151617610dfd578f90610d5a98610d346101009f9e9d9c9b978f8f9b610d549b610d24926060610d1c610d2d968f610d4e9f60029f90610d439f610d1092610d3e9f610d05610d00610d0a94610b32610b3294611341565b611c33565b611341565b90610a56565b905260c08c0151611bf3565b910152611911565b92429051611093565b8092611bf3565b9e8f930151611bf3565b610a6e565b05985191518a610a56565b9061135e565b05611425565b91610d8085610b32610d7a87610d718c518961135e565b058d5190610a56565b95611341565b809401938412600116610dd3575050610b37969593610b32610d05610dc5610dcd96610d0a610db9610b329b98610b32610b2299611341565b975191610b3289611341565b948951610a6e565b92610b2a565b6011907f4e487b71000000000000000000000000000000000000000000000000000000005f52525ffd5b8960118c7f4e487b71000000000000000000000000000000000000000000000000000000005f52525ffd5b898e517fa9c8b14d000000000000000000000000000000000000000000000000000000008152fd5b898f858d9151917fca78c8a4000000000000000000000000000000000000000000000000000000008352820152fd5b6044918789928e51937fb1c4aefb000000000000000000000000000000000000000000000000000000008552840152820152fd5b508115610c48565b8787918d51917f1ca41876000000000000000000000000000000000000000000000000000000008352820152fd5b866011897f4e487b71000000000000000000000000000000000000000000000000000000005f52525ffd5b866012897f4e487b71000000000000000000000000000000000000000000000000000000005f52525ffd5b858a517fb2094b59000000000000000000000000000000000000000000000000000000008152fd5b836041867f4e487b71000000000000000000000000000000000000000000000000000000005f52525ffd5b90918093995082813d831161105e575b610fac81836106f4565b810103126100f057875192830183811067ffffffffffffffff82111761103357885281518352602082015160208401528782015188840152606082015190811681036100f05760608301526080810151608083015260a081015160a083015260c081015160c083015260e081015160e08301526101008091015190820152955f8080610aee565b896041867f4e487b71000000000000000000000000000000000000000000000000000000005f52525ffd5b503d610fa2565b88513d5f823e3d90fd5b90670de0b6b3a7640000918281029281840414901517156105a557610651916105e5565b919082039182116105a557565b6040517fe184c9be00000000000000000000000000000000000000000000000000000000815260208160048173ffffffffffffffffffffffffffffffffffffffff86165afa9081156111b1575f9161117f575b5042811161110a57505050670de0b6b3a764000090565b61112761111f6301e133809461112d94611911565b914290611093565b906105d2565b047f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81116100f05761115e90611425565b5f81126100f05780156105ef576ec097ce7bc90715b34b9f10000000000490565b90506020813d6020116111a9575b8161119a602093836106f4565b810103126100f057515f6110f3565b3d915061118d565b6040513d5f823e3d90fd5b73ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000009eaaeda23177b7168c55a3a0f937f67919733449167f00000000000000000000000000000000000000000000000000000000000003847f000000000000000000000000000000000000000000000000000000000000000380600114611330578060021461131f578060031461130957600414611281577f4e487b71000000000000000000000000000000000000000000000000000000005f52605160045260245ffd5b6112916112b8916112df936106bf565b7f0000000000000000000000000000000000000000000000000de0b6b3a7640000906105d2565b7f0000000000000000000000000000000000000000000000000de0b6b3a7640000906105e5565b7f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81116100f05790565b5061131a6112b8916112df9361068c565b611291565b5061131a6112b8916112df93610654565b5061131a6112b8916112df9361061c565b90670de0b6b3a7640000918281029281840514901517156105a557565b81810292915f82127f80000000000000000000000000000000000000000000000000000000000000008214166105a55781840514901517156105a557565b80156105ef576ec097ce7bc90715b34b9f10000000000590565b81156105ef570590565b156113c757565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601060248201527f496e76616c6964206578706f6e656e74000000000000000000000000000000006044820152fd5b7ffffffffffffffffffffffffffffffffffffffffffffffffdc702bd3a30fc0000811215806117ec575b611458906113c0565b5f81126117d8576064906806f05b59d3b20000008112611775577ffffffffffffffffffffffffffffffffffffffffffffffff90fa4a62c4e0000000168056bc75e2d6310000082770195e54c5dd42177f53a27172fa9ec630262827000000000925b02819068ad78ebc5ac6200000081121561173c575b6856bc75e2d631000000811215611702575b682b5e3af16b188000008112156116ca575b6815af1d78b58c400000811215611692575b680ad78ebc5ac620000081121561165b575b82811215611624575b6802b5e3af16b18800008112156115ed575b68015af1d78b58c400008112156115b6575b60028382800205056003848383020505600485848302050585600581868402050560068287830205056007838883020505906008848984020505926009858a8602050595600a868b8902050597600b878c8b02050599600c888d8d0205059b0101010101010101010101010205020590565b6806f5f17757889379377ffffffffffffffffffffffffffffffffffffffffffffffffea50e2874a73c000084920192020590611544565b6808f00f760a4b2db55d7ffffffffffffffffffffffffffffffffffffffffffffffffd4a1c50e94e78000084920192020590611532565b680ebc5fb417461211107ffffffffffffffffffffffffffffffffffffffffffffffffa9438a1d29cf0000084920192020590611520565b68280e60114edb805d037ffffffffffffffffffffffffffffffffffffffffffffffff5287143a539e0000084920192020590611517565b690127fa27722cc06cc5e27fffffffffffffffffffffffffffffffffffffffffffffffea50e2874a73c0000084920192020590611505565b693f1fce3da636ea5cf8507fffffffffffffffffffffffffffffffffffffffffffffffd4a1c50e94e7800000849201920205906114f3565b6b02df0ab5a80a22c61ab5a7007fffffffffffffffffffffffffffffffffffffffffffffffa9438a1d29cf000000849201920205906114e1565b6e01855144814a7ff805980ff008400091507fffffffffffffffffffffffffffffffffffffffffffffff5287143a539e000000016114cf565b6803782dace9d900000081126117c5577ffffffffffffffffffffffffffffffffffffffffffffffffc87d25316270000000168056bc75e2d63100000826b1425982cf597cd205cef7380926114ba565b68056bc75e2d63100000826001926114ba565b6117e3905f03611425565b6106519061139c565b5068070c1cc73b00c8000081131561144f565b5f8212156118b2577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff915b5f81131561187657670de0b6b3a764000091611845916105d2565b047f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81116100f0576106519161135e565b7f800000000000000000000000000000000000000000000000000000000000000081146105a557670de0b6b3a764000091611845915f036105d2565b60019161182a565b519081600f0b82036100f057565b519061ffff821682036100f057565b8051156118e45760200190565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b9063ffffffff809116908115611af6576040928351606081019167ffffffffffffffff928281108482111761073557865260028252602091828101873682378661195a836118d7565b5287519586927f883bdbfd0000000000000000000000000000000000000000000000000000000084526024840190866004860152518091526044840192915f905b87838310611ad9575050505050918173ffffffffffffffffffffffffffffffffffffffff815f950392165afa928315611acf575f93611a22575b5050508051600110156118e457611a10927affffffffffffffffffffffffffffffffffffffffffffffffffffff9384809284015116926118d7565b511690038281116105a5578216041690565b909192503d805f833e611a3581836106f4565b81019082818303126100f0578051908482116100f0570181601f820112156100f0578051938411610735578360051b90865194611a74858401876106f4565b855283808601928201019283116100f0578301905b828210611a9c57505050505f80806119d5565b81517affffffffffffffffffffffffffffffffffffffffffffffffffffff811681036100f0578152908301908301611a89565b85513d5f823e3d90fd5b8451821686528a965094850194909301926001919091019061199b565b505060c073ffffffffffffffffffffffffffffffffffffffff916004604051809481937fc3fb90d6000000000000000000000000000000000000000000000000000000008352165afa80156111b1575f90611b5f575b6bffffffffffffffffffffffff91501690565b5060c0813d60c011611beb575b81611b7960c093836106f4565b810103126100f057611b8a816118ba565b50611b97602082016118ba565b5060408101516bffffffffffffffffffffffff811681036100f057611be560a083611bd160606bffffffffffffffffffffffff96016118c8565b50611bde608082016118c8565b50016118c8565b50611b4c565b3d9150611b6c565b6301e1338091611c02916105d2565b047f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81116100f05761065190611425565b5f811315611d155780670c7d713b49da00001280611d04575b15611cfb57670de0b6b3a7640000906ec097ce7bc90715b34b9f100000000090611c9f908302828101907fffffffffffffffffffffffffffffffffff3f68318436f8ea4cb460f0000000000183026113b6565b9080828002059181838202058284820205838582020591848684020593858786020595808888020597880205600f900596600d900595600b900594600990059360079005926005900591600390050101010101010160011b0590565b61065190611d73565b50670f43fc2c04ee00008112611c4c565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600d60248201527f6f7574206f6620626f756e6473000000000000000000000000000000000000006044820152fd5b670de0b6b3a764000081126120a7576064905f7e1600ef3172e58d2e933ec884fde10064c63b5372d805e203c000000000000082121561207c575b73011798004d755d3c8bc8e03204cf44619e00000082121561205b575b820290808302906e01855144814a7ff805980ff00840009081831215612038575b50506b02df0ab5a80a22c61ab5a70080821215612018575b50693f1fce3da636ea5cf85080821215611ff8575b50690127fa27722cc06cc5e280821215611fd8575b5068280e60114edb805d0380821215611fb8575b50680ebc5fb4174612111080821215611fa1575b506808f00f760a4b2db55d80821215611f81575b506806f5f177578893793780821215611f61575b506806248f33704b28660380821215611f42575b506805c548670b9510e7ac80821215611f23575b50611ee268056bc75e2d6310000091827ffffffffffffffffffffffffffffffffffffffffffffffffa9438a1d29cf000008183019201026113b6565b9080828002059181838202058284820205916003600560076009600b888a89020598808b8b02059a8b0205059805960594059205010101010160011b010590565b68056bc75e2d631000006756bc75e2d63100009202059101905f611ea6565b68056bc75e2d6310000067ad78ebc5ac6200009202059101905f611e92565b68056bc75e2d6310000068015af1d78b58c400009202059101905f611e7e565b68056bc75e2d631000006802b5e3af16b18800009202059101905f611e6a565b68056bc75e2d63100000809202059101905f611e56565b68056bc75e2d63100000680ad78ebc5ac62000009202059101905f611e42565b68056bc75e2d631000006815af1d78b58c4000009202059101905f611e2e565b68056bc75e2d63100000682b5e3af16b188000009202059101905f611e19565b68056bc75e2d631000006856bc75e2d6310000009202059101905f611e04565b68ad78ebc5ac62000000925069021e19e0c9bab240000002059101905f80611dec565b906b1425982cf597cd205cef73806803782dace9d900000091059101611dcb565b50770195e54c5dd42177f53a27172fa9ec63026282700000000090056806f05b59d3b2000000611dae565b6120b36120b89161139c565b611d73565b5f039056fea26469706673582212209ff8249c142f6e0885939c4c49a82698a874e81534c962938dd51150f70e839d64736f6c63430008180033","source_code":"// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity ^0.8.17;\n\nimport \"../../../interfaces/IPChainlinkOracle.sol\";\nimport \"../PendleLpOracleLib.sol\";\n\n/**\n * @dev The round data returned from this contract will follow:\n * - There will be only one round (roundId=0)\n * - startedAt=0, updatedAt=block.timestamp\n */\ncontract PendleChainlinkOracle is IPChainlinkOracle {\n    error InvalidRoundId();\n\n    // solhint-disable immutable-vars-naming\n    address public immutable factory;\n\n    address public immutable market;\n    uint32 public immutable twapDuration;\n    PendleOracleType public immutable baseOracleType;\n\n    uint256 public immutable fromTokenScale;\n    uint256 public immutable toTokenScale;\n\n    function(IPMarket, uint32) internal view returns (uint256) private immutable _getRawPendlePrice;\n\n    modifier roundIdIsZero(uint80 roundId) {\n        if (roundId != 0) {\n            revert InvalidRoundId();\n        }\n        _;\n    }\n\n    constructor(address _market, uint32 _twapDuration, PendleOracleType _baseOracleType) {\n        factory = msg.sender;\n        market = _market;\n        twapDuration = _twapDuration;\n        baseOracleType = _baseOracleType;\n        (uint256 fromTokenDecimals, uint256 toTokenDecimals) = _readDecimals(_market, _baseOracleType);\n        (fromTokenScale, toTokenScale) = (10 ** fromTokenDecimals, 10 ** toTokenDecimals);\n        _getRawPendlePrice = _getRawPendlePriceFunc();\n    }\n\n    // =================================================================\n    //                          CHAINLINK INTERFACE\n    // =================================================================\n\n    /**\n     * @notice The round data returned from this contract will follow:\n     * - answer will satisfy 1 natural unit of PendleToken = (answer/1e18) natural unit of OutputToken\n     * - In other words, 10**(PendleToken.decimals) = (answer/1e18) * 10**(OutputToken.decimals)\n     * @param roundId always 0 for this contract\n     * @param answer The answer (in 18 decimals)\n     * @param startedAt always 0 for this contract\n     * @param updatedAt always block.timestamp for this contract\n     * @param answeredInRound always 0 for this contract\n     */\n    function latestRoundData()\n        public\n        view\n        virtual\n        returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound)\n    {\n        roundId = 0;\n        answer = _getPendleTokenPrice();\n        startedAt = 0;\n        updatedAt = block.timestamp;\n        answeredInRound = 0;\n    }\n\n    function getRoundData(\n        uint80 roundId\n    ) external view roundIdIsZero(roundId) returns (uint80, int256, uint256, uint256, uint80) {\n        return latestRoundData();\n    }\n\n    function decimals() external pure returns (uint8) {\n        return 18;\n    }\n\n    function description() external pure returns (string memory) {\n        return \"Pendle Chainlink-compatible Oracle\";\n    }\n\n    function version() external pure returns (uint256) {\n        return 1;\n    }\n\n    // =================================================================\n    //                          PRICING FUNCTIONS\n    // =================================================================\n\n    function _getPendleTokenPrice() internal view returns (int256) {\n        return _descalePrice(_getRawPendlePrice(IPMarket(market), twapDuration));\n    }\n\n    function _descalePrice(uint256 price) private view returns (int256 unwrappedPrice) {\n        return PMath.Int((price * fromTokenScale) / toTokenScale);\n    }\n\n    // =================================================================\n    //                          USE ONLY AT INITIALIZATION\n    // =================================================================\n\n    function _getRawPendlePriceFunc()\n        internal\n        view\n        returns (function(IPMarket, uint32) internal view returns (uint256))\n    {\n        if (baseOracleType == PendleOracleType.PT_TO_SY) {\n            return PendlePYOracleLib.getPtToSyRate;\n        } else if (baseOracleType == PendleOracleType.PT_TO_ASSET) {\n            return PendlePYOracleLib.getPtToAssetRate;\n        } else if (baseOracleType == PendleOracleType.LP_TO_SY) {\n            return PendleLpOracleLib.getLpToSyRate;\n        } else if (baseOracleType == PendleOracleType.LP_TO_ASSET) {\n            return PendleLpOracleLib.getLpToAssetRate;\n        } else {\n            revert(\"not supported\");\n        }\n    }\n\n    function _readDecimals(\n        address _market,\n        PendleOracleType _oracleType\n    ) internal view returns (uint8 _fromDecimals, uint8 _toDecimals) {\n        (IStandardizedYield SY, , ) = IPMarket(_market).readTokens();\n\n        uint8 syDecimals = SY.decimals();\n        (, , uint8 assetDecimals) = SY.assetInfo();\n\n        if (_oracleType == PendleOracleType.PT_TO_ASSET) {\n            return (assetDecimals, assetDecimals);\n        } else if (_oracleType == PendleOracleType.PT_TO_SY) {\n            return (assetDecimals, syDecimals);\n        } else if (_oracleType == PendleOracleType.LP_TO_ASSET) {\n            return (18, assetDecimals);\n        } else if (_oracleType == PendleOracleType.LP_TO_SY) {\n            return (18, syDecimals);\n        } else {\n            revert(\"not supported\");\n        }\n    }\n}\n","creation_status":"success","file_path":"contracts/oracles/PtYtLpOracle/chainlink/PendleChainlinkOracle.sol"}