### Example: Resolve PT/YT and Get Supported Tokens (JavaScript) Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/RouterStatic/ApiReference/InfoFunctions Demonstrates how to use `getPY` to resolve a PT/YT pair and `getTokensInOut` to find supported tokens for a given market address using the Pendle SDK. ```javascript // You only have one token from the pair — get both const [ptAddress, ytAddress] = await routerStatic.getPY(knownPtOrYtAddress); // Find out what tokens are accepted for swapping/minting const [tokensIn, tokensOut] = await routerStatic.getTokensInOut(MARKET_ADDRESS); console.log("Accepted input tokens:", tokensIn); console.log("Accepted output tokens:", tokensOut); ``` -------------------------------- ### Basic Liquidity Addition Example Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/PendleRouter/ApiReference/LiquidityFunctions Example demonstrating how to add liquidity using the `addLiquiditySingleToken` function with USDe. Ensure you have the necessary market and token addresses defined. ```javascript // Add liquidity with USDe router.addLiquiditySingleToken( msg.sender, PT_USDE_MARKET_ADDRESS, minLpOut, createDefaultApproxParams(), createTokenInputSimple(USDE_ADDRESS, 1000e18), createEmptyLimitOrderData() ); ``` -------------------------------- ### Direct SY to YT Trading Example Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/PendleRouter/ApiReference/YtFunctions Example of swapping SY tokens directly for YT tokens. This is a direct trading path between SY and YT without intermediate steps. ```javascript // Swap SY tokens directly for YT tokens router.swapExactSyForYt( msg.sender, MARKET_ADDRESS, syAmount, minYtOut, createDefaultApproxParams(), createEmptyLimitOrderData() ); ``` -------------------------------- ### Pendle V2 Integration Example Source: https://docs.pendle.finance/pendle-v2-dev/Contracts/YieldTokenization This Solidity code demonstrates a full integration flow with Pendle V2 contracts. It covers looking up or creating PT/YT pairs, depositing SY to mint PT/YT, redeeming SY by burning PT/YT (both pre and post-expiry), and claiming interest and rewards. Note: This example is for illustration and is not audited; use with caution. ```solidity // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; IPYieldContractFactory factory; // PendleYieldContractFactoryUpg address SY; uint32 expiry; address receiver; // --- Step 1: Look up or create a PT/YT pair --- // Check if the pair already exists address PT = factory.getPT(SY, expiry); address YT = factory.getYT(SY, expiry); if (PT == address(0)) { // Create a new yield contract if it doesn't exist yet (PT, YT) = factory.createYieldContract(SY, expiry, true); } IPYieldToken yt = IPYieldToken(YT); IStandardizedYield sy = IStandardizedYield(SY); IPrincipalToken pt = IPrincipalToken(PT); // --- Step 2: Mint PT + YT by depositing SY --- IERC20(address(sy)).transfer(address(yt), 100e18); // deposit 100 SY uint256 amountPYOut = yt.mintPY(receiver, receiver); // receive PT + YT // --- Step 3a: Redeem SY by burning PT + YT (pre-expiry) --- IERC20(address(pt)).transfer(address(yt), amountPYOut); // send PT IERC20(address(yt)).transfer(address(yt), amountPYOut); // send YT uint256 amountSyOut = yt.redeemPY(receiver); // receive SY // --- Step 3b: Redeem SY by burning PT only (post-expiry) --- // After expiry, YT has no remaining value; only PT is required. IERC20(address(pt)).transfer(address(yt), amountPYOut); // send PT only uint256 amountSyOut = yt.redeemPY(receiver); // receive SY // --- Step 4: Claim accrued interest (in SY) and rewards --- (uint256 interestOut, uint256[] memory rewardsOut) = yt.redeemDueInterestAndRewards( receiver, true, // claim interest true // claim rewards ); ``` -------------------------------- ### Basic Liquidity Removal Example Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/PendleRouter/ApiReference/LiquidityFunctions Example demonstrating how to remove liquidity to USDe using the `removeLiquiditySingleToken` function. This requires the market address and the amount of LP tokens to remove. ```javascript // Remove liquidity to USDe router.removeLiquiditySingleToken( msg.sender, PT_USDE_MARKET_ADDRESS, lpAmount, createTokenOutputSimple(USDE_ADDRESS, minUsdeOut), createEmptyLimitOrderData() ); ``` -------------------------------- ### Deploying LP Oracle and Wrapping Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/Oracle/LinearDiscountOracle/LinearDiscountOracleWrapper This example shows how to deploy a `PendleLpLinearDiscountOracle` via its factory and then manually wrap it with `PendleLinearDiscountOracleWrapper` to satisfy staleness checks. ```solidity address lpOracle = lpFactory.create(market, baseLpDiscountPerYear, lpMaturedPrice); address lpWrapped = address(new PendleLinearDiscountOracleWrapper(lpOracle)); ``` -------------------------------- ### Buying YT-sUSDe with USDe Example Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/PendleRouter/ApiReference/YtFunctions Example of swapping USDe for YT-sUSDe tokens. Ensure the correct market address and token amounts are used. This function is for buying YT tokens. ```javascript // Swap 1000 USDe for YT-sUSDe tokens router.swapExactTokenForYt( msg.sender, PT_SUSDE_MARKET_ADDRESS, minYtOut, createDefaultApproxParams(), createTokenInputSimple(USDE_ADDRESS, 1000e18), createEmptyLimitOrderData() ); ``` -------------------------------- ### Selling YT-sUSDe for USDe Example Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/PendleRouter/ApiReference/YtFunctions Example of swapping YT-sUSDe tokens back to USDe. This function is used for selling YT tokens to receive underlying tokens. ```javascript // Swap YT-sUSDe tokens for USDe router.swapExactYtForToken( msg.sender, PT_SUSDE_MARKET_ADDRESS, ytAmount, createTokenOutputSimple(USDE_ADDRESS, minUsdeOut), createEmptyLimitOrderData() ); ``` -------------------------------- ### Install Pendle AI Plugin Source: https://docs.pendle.finance/cn/pendle-v2/AppGuide/PendleAI Use these commands to install the Pendle AI plugin and its dependencies via the Claude Code plugin marketplace. Ensure you have Node.js version 20 or higher installed. ```bash /plugin marketplace add pendle-finance/pendle-ai /plugin install pendle-v2 ``` -------------------------------- ### Claiming LP Rewards Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/PendleMarket Example code demonstrating how to discover reward tokens and claim all accumulated LP rewards for a user. ```Solidity // Discover what reward tokens this market distributes address[] memory rewardTokens = market.getRewardTokens(); // Claim all accumulated rewards for msg.sender uint256[] memory rewardAmounts = market.redeemRewards(msg.sender); // rewardAmounts[i] corresponds to rewardTokens[i] for (uint256 i = 0; i < rewardTokens.length; i++) { // handle rewardTokens[i] with amount rewardAmounts[i] } ``` -------------------------------- ### Basic Swap Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/PendleMarket Example code for executing a basic swap, transferring PT to the market and then performing an exact PT in for SY out swap. ```Solidity // Transfer PT to market first pt.transfer(address(market), ptAmount); // Execute swap (exact PT in → SY out) (uint256 syOut,) = market.swapExactPtForSy( msg.sender, ptAmount, "" ); ``` -------------------------------- ### Basic Mint Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/PendleMarket Example code for minting LP tokens by first transferring SY and PT to the market, then calling the mint function. ```Solidity // Transfer tokens first sy.transfer(address(market), syAmount); pt.transfer(address(market), ptAmount); // Mint LP tokens (uint256 lpOut,,) = market.mint( msg.sender, syAmount, ptAmount ); ``` -------------------------------- ### Get Input/Output Tokens for a Market Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/RouterStatic/ApiReference/InfoFunctions Retrieve the lists of tokens that can be used as input or output for a given SY, PT/YT, or Market address. Useful for populating token-selection UI or validating supported tokens before a swap. ```solidity function getTokensInOut(address token) external view returns (address[] memory tokensIn, address[] memory tokensOut) ``` -------------------------------- ### Get User Market Info Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/RouterStatic/ApiReference/InfoFunctions Fetch a user's LP balance, the equivalent PT and SY values, and any unclaimed LP rewards. Use this to display a user's liquidity position and pending reward claims. ```solidity function getUserMarketInfo(address market, address user) external returns (UserMarketInfo memory res) ``` -------------------------------- ### Deployment via Factory Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/Oracle/LinearDiscountOracle/LpLinearDiscountOracle Deploy the LP Linear Discount Oracle using the PendleLpLinearDiscountOracleFactory. The `create` function takes the market address, base LP discount per year, and the target LP matured price. ```APIDOC ## Deployment via Factory Deploy via `PendleLpLinearDiscountOracleFactory`. ```solidity function create( address market, uint256 baseLpDiscountPerYear, uint256 lpMaturedPrice ) external returns (address); ``` ### Parameters * `market` (address): The `PendleMarket` (LP token) address. * `baseLpDiscountPerYear` (uint256): Annual discount slope in wad (`1e18 = 100%/year`). * `lpMaturedPrice` (uint256): Target LP price at maturity in wad; must be `>= 1e18`. ### Manual Wrapper for `updatedAt` Staleness To satisfy protocols checking `updatedAt` staleness, wrap the oracle manually after deployment: ```solidity address lpOracle = lpFactory.create(market, baseLpDiscountPerYear, lpMaturedPrice); address lpWrapped = address(new PendleLinearDiscountOracleWrapper(lpOracle)); ``` ``` -------------------------------- ### Deploy LP Linear Discount Oracle Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/Oracle/LinearDiscountOracle/LpLinearDiscountOracle Use the PendleLpLinearDiscountOracleFactory to create an oracle instance. Provide the market address, annual discount slope, and target LP price at maturity. ```solidity function create( address market, uint256 baseLpDiscountPerYear, uint256 lpMaturedPrice ) external returns (address); ``` -------------------------------- ### PendleLPWrapperFactory - rewardReceiver Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/PendleMarket/LPWrapper Get the address where harvested rewards are sent. ```APIDOC ## rewardReceiver ### Description Returns the address designated for receiving harvested rewards. ### Method `view` ### Signature `function rewardReceiver() external view returns (address)` ``` -------------------------------- ### Deploying the Oracle Source: https://docs.pendle.finance/cn/pendle-v2-dev/Oracles/DeterministicOracles/LPLinearDiscountOracle The LPLinearDiscountOracle can be deployed using the `lpLinearDiscountOracleFactory`. The factory provides a `create` method to deploy new oracle instances. ```APIDOC ## Deployment The oracle can be deployed using the `lpLinearDiscountOracleFactory`. The address of the factory can be found in the Deployments on GitHub sections, under the `"lpLinearDiscountOracleFactory"` field. The factory has a method to help with oracle deployment: ```solidity function create(address market, uint256 basePtDiscountPerYear, uint256 lpMaturedPrice) external returns (address res); ``` ``` -------------------------------- ### Get YT to SY Rate Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/Oracle/PYLpOracle Returns the TWAP rate of YT in SY terms. ```solidity function getYtToSyRate(address market, uint32 duration) external view returns (uint256); ``` -------------------------------- ### Deploy LP Linear Discount Oracle Source: https://docs.pendle.finance/cn/pendle-v2-dev/Oracles/DeterministicOracles/LPLinearDiscountOracle Use the `lpLinearDiscountOracleFactory` to deploy a new LP Linear Discount Oracle. Provide the market address, base PT discount per year, and the LP matured price. ```Solidity function create(address market, uint256 basePtDiscountPerYear, uint256 lpMaturedPrice) external returns (address res); ``` -------------------------------- ### Deploy Common Market with Liquidity Seeding Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/StandardizedYield/CommonSY Deploys an SY, creates a Pendle market, and seeds initial liquidity in a single transaction. Requires PoolConfig and token details for seeding. ```Solidity function deployCommonMarketById( bytes32 id, bytes memory constructorParams, bytes memory initData, PoolConfig memory config, address tokenToSeedLiquidity, uint256 amountToSeed, address syOwner ) external returns (PoolDeploymentAddrs memory); ``` -------------------------------- ### Get Oracle Decimals Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/Oracle/LinearDiscountOracle/LpLinearDiscountOracle Returns the number of decimals used by the oracle, which is always 18. ```solidity function decimals() external pure returns (uint8); // returns 18 ``` -------------------------------- ### Deploy Upgradable SY Contract Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/StandardizedYield/CommonSY Deploys an implementation contract and wraps it in a Transparent Upgradeable Proxy. Use the returned proxy address as the SY address. ```Solidity function deployUpgradableSY( bytes32 id, bytes memory constructorParams, // abi-encoded constructor args for the implementation bytes memory initData, // abi-encoded initialize(...) call for the proxy address syOwner ) external returns (address SY); // returns the proxy address ``` -------------------------------- ### PendleLPWrapper - LP Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/PendleMarket/LPWrapper Get the address of the underlying Pendle LP token that this wrapper contract is associated with. ```APIDOC ## LP ### Description Returns the address of the underlying Pendle LP token this wrapper is backed by. ### Method `view` ### Signature `function LP() external view returns (address)` ``` -------------------------------- ### Simulate Swap Exact Token for YT Static Source: https://docs.pendle.finance/pendle-v2-dev/Contracts/RouterStatic/ApiReference/SwapFunctions Simulates buying Yield Tokens (YT) with a specified amount of an arbitrary input token. Returns the expected YT output, SY minted, SY fee, price impact, and the exchange rate after the trade. ```solidity function swapExactTokenForYtStatic(address market, address tokenIn, uint256 amountTokenIn) external view returns ( uint256 netYtOut, uint256 netSyMinted, uint256 netSyFee, uint256 priceImpact, uint256 exchangeRateAfter ) ``` -------------------------------- ### Get LP to SY Rate Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/Oracle/PYLpOracle Returns the approximate TWAP rate of one LP token in SY terms. ```solidity function getLpToSyRate(address market, uint32 duration) external view returns (uint256); ``` -------------------------------- ### Contract Reference - getLpDiscount Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/Oracle/LinearDiscountOracle/LpLinearDiscountOracle Public view function to get the raw discount for a given time left until maturity. ```APIDOC ### `getLpDiscount` ```solidity function getLpDiscount(uint256 timeLeft) public view returns (uint256); ``` Returns the raw discount for a given `timeLeft` in seconds: ``` lpDiscount = timeLeft * baseLpDiscountPerYear / SECONDS_PER_YEAR ``` ``` -------------------------------- ### Simulate Swap Exact SY for YT Static Source: https://docs.pendle.finance/pendle-v2-dev/Contracts/RouterStatic/ApiReference/SwapFunctions Simulates buying Yield Tokens (YT) with a specified amount of Supplied Yield (SY). Returns the expected YT output, SY fee, price impact, and the exchange rate after the trade. ```solidity function swapExactSyForYtStatic(address market, uint256 exactSyIn) external view returns (uint256 netYtOut, uint256 netSyFee, uint256 priceImpact, uint256 exchangeRateAfter) ``` -------------------------------- ### Constructor Parameters for PendleERC20WithAdapterSY Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/StandardizedYield/CommonSY Defines the constructor parameters required for deploying an `PendleERC20WithAdapterSY` contract. Use `address(0)` for the adapter if none is needed initially; it can be set later. ```solidity bytes memory constructorParams = abi.encode( address _erc20, address _offchainRewardManager ); bytes memory initData = abi.encodeWithSelector( PendleERC20WithAdapterSY.initialize.selector, string _name, // e.g. "SY USDS" string _symbol, // e.g. "SY-USDS" address _adapter // address(0) if no adapter needed at deploy time ); ``` -------------------------------- ### Get Reward Receiver Address - PendleLPWrapperFactory Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/PendleMarket/LPWrapper Returns the address designated to receive rewards harvested from the LP wrapper contracts. ```solidity function rewardReceiver() external view returns (address); ``` -------------------------------- ### Contract Reference - getLpPrice Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/Oracle/LinearDiscountOracle/LpLinearDiscountOracle Public view function to get the LP price factor for a given time left until maturity. ```APIDOC ### `getLpPrice` ```solidity function getLpPrice(uint256 timeLeft) public view returns (uint256); ``` Returns the LP price factor for a given `timeLeft` in seconds. This is the same value as the `answer` in `latestRoundData()`. ``` -------------------------------- ### Buy YT with Token using Router Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/PendleRouter/ContractIntegrationGuide Executes a trade to buy YT tokens using an underlying asset like wstETH. Approves the router to spend the input token and calls `swapExactTokenForYt`. ```Solidity address market = 0xD0354D4e7bCf345fB117cabe41aCaDb724eccCa2; address wstETH = 0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0; address ytReceiver = address(this); IERC20(wstETH).approve(address(router), tokenAmount); (uint256 netYtOut, , ) = router.swapExactTokenForYt( ytReceiver, // receiver address(market), // market address 0, // minYtOut defaultApprox, // approximation params createTokenInputStruct(wstETH, tokenAmount), // token input emptyLimit // limit order data ); ``` -------------------------------- ### Example Rate Limit Response Headers Source: https://docs.pendle.finance/pendle-v2-dev/Backend/ApiOverview These headers are returned in API responses to help monitor usage and understand rate limiting. ```text x-computing-unit: 25 x-ratelimit-limit: 100 x-ratelimit-remaining: 75 x-ratelimit-reset: 1724206817 x-ratelimit-weekly-limit: 200000 x-ratelimit-weekly-remaining: 175000 x-ratelimit-weekly-reset: 1724206817 ``` -------------------------------- ### PendleSparkLinearDiscountOracleFactoryWrapper.createWithPt Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/Oracle/LinearDiscountOracle/LinearDiscountOracleWrapper Deploys a `PendleSparkLinearDiscountOracle` for a given PT address and then wraps it. Returns the address of the newly created wrapper contract. ```solidity function createWithPt( address pt, uint256 baseDiscountPerYear ) external returns (address wrapper); ``` -------------------------------- ### Simulate Redeeming PT/YT to SY - Solidity Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/RouterStatic/ApiReference/MintRedeemFunctions Simulates redeeming PT and YT back into SY. Requires equal amounts of PT and YT as input. ```solidity function redeemPyToSyStatic(address YT, uint256 netPYToRedeem) external view returns (uint256 netSyOut) ``` -------------------------------- ### Simulate Swap Exact YT for Token Static Source: https://docs.pendle.finance/pendle-v2-dev/Contracts/RouterStatic/ApiReference/SwapFunctions Simulates selling an exact amount of Yield Tokens (YT) for a specified output token. Returns the output token amount, SY fee, price impact, exchange rate, intermediate SY amount, SY owed for interest, PY used to repay interest, and PY redeemed for SY output. ```solidity function swapExactYtForTokenStatic(address market, uint256 exactYtIn, address tokenOut) external view returns ( uint256 netTokenOut, uint256 netSyFee, uint256 priceImpact, uint256 exchangeRateAfter, uint256 netSyOut, uint256 netSyOwedInt, uint256 netPYToRepaySyOwedInt, uint256 netPYToRedeemSyOutInt ) ``` -------------------------------- ### Get Underlying LP Token Address - PendleLPWrapper Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/PendleMarket/LPWrapper Returns the address of the Pendle LP token that the current wrapper contract is associated with. ```solidity function LP() external view returns (address); ``` -------------------------------- ### Simulate Minting SY from Token - Solidity Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/RouterStatic/ApiReference/MintRedeemFunctions Simulates minting SY from a specified input token. Use this to estimate SY output for a given token input amount. ```solidity function mintSyFromTokenStatic(address SY, address tokenIn, uint256 netTokenIn) external view returns (uint256 netSyOut) ``` -------------------------------- ### Get LP Price Factor Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/Oracle/LinearDiscountOracle/LpLinearDiscountOracle Returns the LP price factor for a given time left in seconds. This is the same value as the 'answer' in latestRoundData(). ```solidity function getLpPrice(uint256 timeLeft) public view returns (uint256); ``` -------------------------------- ### Simulate Swap Exact Token for YT Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/RouterStatic/ApiReference/SwapFunctions Simulates buying Yield Tokens (YT) with an exact amount of an arbitrary input token. Returns the expected YT output, minted SY, SY fee, price impact, and the exchange rate after the trade. ```solidity function swapExactTokenForYtStatic(address market, address tokenIn, uint256 amountTokenIn) external view returns ( uint256 netYtOut, uint256 netSyMinted, uint256 netSyFee, uint256 priceImpact, uint256 exchangeRateAfter ) ``` -------------------------------- ### Simulate Swap Exact SY for YT Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/RouterStatic/ApiReference/SwapFunctions Simulates buying Yield Tokens (YT) with an exact amount of Share Tokens (SY). Returns the expected YT output, SY fee, price impact, and the exchange rate after the trade. ```solidity function swapExactSyForYtStatic(address market, uint256 exactSyIn) external view returns (uint256 netYtOut, uint256 netSyFee, uint256 priceImpact, uint256 exchangeRateAfter) ``` -------------------------------- ### Get Asset Information for SY Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/StandardizedYield Retrieves metadata about the underlying asset that the SY contract appreciates against. This includes the asset type, its address, and decimal precision. ```solidity (AssetType assetType, address assetAddress, uint8 assetDecimals) = sy.assetInfo(); ``` -------------------------------- ### Deploy Normal Market Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/PendleMarket/CommonMarketDeployments Use this function when you have already deployed a custom SY and want to create the PT/YT pair and market around it. This is callable by anyone. ```APIDOC ## deploy5115MarketAndSeedLiquidity ### Description Creates a Pendle market (PT/YT pair) around an already deployed custom SY contract and seeds initial liquidity. ### Method `public payable` ### Parameters #### Path Parameters - **SY** (`address`) - Description: The address of your already-deployed SY contract. - **config** (`PoolConfig`) - Description: Market parameters including expiry, rate limits, desired rate, and fee. - **tokenToSeedLiquidity** (`address`) - Description: The token address to use for seeding initial liquidity. ETH is accepted natively. - **amountToSeed** (`uint256`) - Description: The amount of `tokenToSeedLiquidity` to use for seeding. ### Returns - **PoolDeploymentAddrs** - An object containing the addresses of the SY, PT, YT, and market contracts. ``` -------------------------------- ### Get PT to SY Rate Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/Oracle/PYLpOracle Returns the TWAP rate of PT denominated in SY. This is the recommended rate for collateral pricing due to its native guarantee. ```solidity function getPtToSyRate(address market, uint32 duration) external view returns (uint256); ``` -------------------------------- ### Get Oracle State Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/Oracle/PYLpOracle Retrieves the current state of the oracle for a given market and duration. Ensure `increaseCardinalityRequired` is false and `oldestObservationSatisfied` is true before using the oracle. ```solidity function getOracleState(address market, uint32 duration) external view returns ( bool increaseCardinalityRequired, uint16 cardinalityRequired, bool oldestObservationSatisfied ); ``` -------------------------------- ### Get Wrapper Address - PendleLPWrapperFactory Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/PendleMarket/LPWrapper Retrieves the address of the wrapper contract for a given Pendle LP token. Returns the zero address if no wrapper exists. ```solidity function wrappers(address LP) external view returns (address wrapper); ``` -------------------------------- ### Get Raw LP Discount Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/Oracle/LinearDiscountOracle/LpLinearDiscountOracle Calculates and returns the raw discount for a given time left in seconds using the formula: timeLeft * baseLpDiscountPerYear / SECONDS_PER_YEAR. ```solidity function getLpDiscount(uint256 timeLeft) public view returns (uint256); ``` -------------------------------- ### Get Stored SY Reward Indexes Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/LiquidityMining/Rewards Views the cached reward indexes without triggering an update. Use this if you only need the last known index values. ```solidity function rewardIndexesStored() external view returns (uint256[] memory indexes); ``` -------------------------------- ### Simulate Adding Liquidity with SY (Retaining YT) Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/RouterStatic/ApiReference/LiquidityFunctions Simulates adding liquidity using SY, with the option to retain any newly minted Yield Tokens (YT). Part of the SY is used to mint PT and YT, with the PT going to the pool and the YT being kept by the user. ```solidity function addLiquiditySingleSyKeepYtStatic(address market, uint256 netSyIn) external view returns (uint256 netLpOut, uint256 netYtOut, uint256 netSyToPY) ``` -------------------------------- ### Get Base Fee Rate Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/PendleMarket Retrieves the base fee rate before any router-specific overrides are applied. This function always returns the original fee set at market creation. ```solidity function getNonOverrideLnFeeRateRoot() external view returns (uint80); ``` -------------------------------- ### Get YT Reward Tokens Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/LiquidityMining/Rewards Retrieves the list of reward token addresses for a Yield Token contract. This function delegates to the underlying Standardized Yield (SY) contract. ```Solidity function getRewardTokens() external view returns (address[] memory tokens); ``` -------------------------------- ### Simulate Minting PT/YT from Token - Solidity Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/RouterStatic/ApiReference/MintRedeemFunctions Simulates minting PT and YT directly from an input token. This involves an implicit conversion from token to SY, then to PT and YT. ```solidity function mintPyFromTokenStatic(address YT, address tokenIn, uint256 netTokenIn) external view returns (uint256 netPyOut) ``` -------------------------------- ### Get Block Cycle Numerator Source: https://docs.pendle.finance/cn/pendle-v2-dev/Contracts/Oracle/PYLpOracle Returns the `blockCycleNumerator`, which encodes the average block time in seconds multiplied by 1000. This is used internally for calculating the minimum ring-buffer cardinality. ```solidity function blockCycleNumerator() external view returns (uint16); ```