How to Integrate PT and LP Oracle
Integrating PT and LP oracles into your system can be accomplished in six easy steps. This document provides detailed instructions along with runnable examples. If you need personalized assistance, don't hesitate to contact us via our Developers channel on Discord.
First, Understand SY, PT, LP
You can read High Level Architecture & StandardizedYield to understand the Pendle system.
Refer to the examples here & here for further understanding.
Second, Choose a Market & Duration
We recommend choosing a market with high trading activities & deep liquidity. For instance, we'll choose EtherFi's weETH market on Arbitrum, which has 70M USD liquidity at block 192_001_277.
The recommended duration is 15 mins (900 secs) or 30 mins (1800 secs), but it can vary depending on the market.
For a detailed guide on assessing the risk, depth of liquidity & twap duration, refer to the corresponding risk assessment docs.
Third, Initialize the Oracle
By default, markets' oracles are un-initialized. You can check the oracle's status & initialize it if necessary using getOracleState
on the PendlePYLpOracle
contract.
Fourth, Get the Price
There are 2 units PT / LP can be denominated in, in SY or in Asset. To get the price in SY, call getPtToSyRate()
, else call getPtToAssetRate()
. Ensure to use the appropriate function as SY price is well defined for some markets, but Asset price is not & vice-versa.
Refer to StandardizedYield docs to call the correct function.
Below is an example of how to call the functions.
If you don't want to use the library, you can call the PendlePtLpOracle
directly though it will take around ~4k additional gas.
(Optional) Fifth, Multiply the Price with a 3rd Price
You can multiply the PT-weETH
to weETH
price by weETH/ETH
price to get the PT-weETH/ETH
price, which is more applicable for money markets.
For example:
Lastly, Handle liquidation & LP's rewards
For PT liquidation
- When a liquidation with as collateral occurs, commonly, the liquidator will have to sell into common asset to pay their debt.
- In Pendle's system, we support converting back to by selling on our AMM (before maturity) or redeeming directly from
PendleYieldToken
contract (post maturity). This will then allow the liquidator to redeem their into one of the output token of (see EIP-5115). - For reference, we have written the
BoringPtSeller
contract to sell into one of the output token. - You can extend this abstract contract to use in a liquidation system.
For LP liquidation
- When a liquidation with as collateral occurs, commonly, the liquidator will have to sell into common asset to pay their debt.
- In Pendle's system, we support converting back to by removing liquidity single-sided into on our AMM (before maturity) or redeeming + and redeeming to directly from
PendleYieldToken
contract (post maturity). This will then allow the liquidator to redeem their into one of the output token of (see EIP-5115). - For reference, we have written the
BoringLpSeller
contract to sell into one of SY's output tokens. - You can extend this abstract contract to use in a liquidation system.
Handling of Pendle LP's rewards:
- Holding Pendle LP tokens will generate PENDLE incentives and potential reward tokens (like WETH for LP for GLP pool)
- The money market contracts will need to redeem these rewards by calling the
redeemRewards
function and implement logic to distribute these rewards to their users