Skip to content

Update pendle #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/pendle-core-v2-public
2 changes: 1 addition & 1 deletion src/adapter/pendle/PendleOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {IPMarket} from "@pendle/core-v2/interfaces/IPMarket.sol";
import {IPPrincipalToken} from "@pendle/core-v2/interfaces/IPPrincipalToken.sol";
import {IPPYLpOracle} from "@pendle/core-v2/interfaces/IPPYLpOracle.sol";
import {IStandardizedYield} from "@pendle/core-v2/interfaces/IStandardizedYield.sol";
import {PendlePYOracleLib} from "@pendle/core-v2/oracles/PendlePYOracleLib.sol";
import {PendlePYOracleLib} from "@pendle/core-v2/oracles/PtYtLpOracle/PendlePYOracleLib.sol";
import {BaseAdapter, Errors, IPriceOracle} from "../BaseAdapter.sol";
import {ScaleUtils, Scale} from "../../lib/ScaleUtils.sol";

Expand Down
26 changes: 18 additions & 8 deletions src/adapter/pendle/PendleUniversalOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {IPMarket} from "@pendle/core-v2/interfaces/IPMarket.sol";
import {IPPrincipalToken} from "@pendle/core-v2/interfaces/IPPrincipalToken.sol";
import {IPPYLpOracle} from "@pendle/core-v2/interfaces/IPPYLpOracle.sol";
import {IStandardizedYield} from "@pendle/core-v2/interfaces/IStandardizedYield.sol";
import {PendlePYOracleLib} from "@pendle/core-v2/oracles/PendlePYOracleLib.sol";
import {PendleLpOracleLib} from "@pendle/core-v2/oracles/PendleLpOracleLib.sol";
import {PendlePYOracleLib} from "@pendle/core-v2/oracles/PtYtLpOracle/PendlePYOracleLib.sol";
import {PendleLpOracleLib} from "@pendle/core-v2/oracles/PtYtLpOracle/PendleLpOracleLib.sol";
import {BaseAdapter, Errors, IPriceOracle} from "../BaseAdapter.sol";
import {ScaleUtils, Scale} from "../../lib/ScaleUtils.sol";

Expand Down Expand Up @@ -60,19 +60,25 @@ contract PendleUniversalOracle is BaseAdapter {
}

(IStandardizedYield sy, IPPrincipalToken pt,) = IPMarket(_pendleMarket).readTokens();
(, address asset,) = sy.assetInfo();

// Note: we allow using any asset pricing to any token.
if (_base == address(pt)) {
if (_quote == address(sy)) {
getRate = PendlePYOracleLib.getPtToSyRate;
} else {
} else if (asset == _quote) {
// Pendle do not recommend to use this type of price
// https://docs.pendle.finance/Developers/Oracles/HowToIntegratePtAndLpOracle
getRate = PendlePYOracleLib.getPtToAssetRate;
} else {
revert Errors.PriceOracle_InvalidConfiguration();
}
} else if (_base == _pendleMarket) {
if (_quote == address(sy)) {
getRate = PendleLpOracleLib.getLpToSyRate;
} else {
} else if (asset == _quote) {
getRate = PendleLpOracleLib.getLpToAssetRate;
} else {
revert Errors.PriceOracle_InvalidConfiguration();
}
} else {
revert Errors.PriceOracle_InvalidConfiguration();
Expand All @@ -82,9 +88,13 @@ contract PendleUniversalOracle is BaseAdapter {
base = _base;
quote = _quote;
twapWindow = _twapWindow;
uint8 baseDecimals = _getDecimals(base);
uint8 quoteDecimals = _getDecimals(quote);
scale = ScaleUtils.calcScale(baseDecimals, quoteDecimals, FEED_DECIMALS);

// We don't need to worry about decimals base and quote decimals scaling,
// Pendle formula to access LP (rawX) in SY (rawY)
// rawY= rawX × lpToSyRate / 10^18
//
// https://docs.pendle.finance/Developers/Oracles/HowToIntegratePtAndLpOracle
scale = ScaleUtils.calcScale(0, 0, FEED_DECIMALS);
}

/// @notice Get a quote by calling the Pendle oracle.
Expand Down