-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d458630
commit 1dcb0dd
Showing
3 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity ^0.8.17; | ||
|
||
import '@pendle/contracts/oracles/PendlePYLpOracle.sol'; | ||
import '@pendle/contracts/interfaces/IPAllActionV3.sol'; | ||
import '@pendle/contracts/interfaces/IPMarket.sol'; | ||
import '@interfaces/oracles/IBaseOracle.sol'; | ||
import {IERC20Metadata} from '@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol'; | ||
|
||
/** | ||
* @title PendleRelayer | ||
* @notice This contracts transforms a Pendle TWAP price feed into a standard IBaseOracle feed | ||
* | ||
*/ | ||
contract PendlePTRelayer is IBaseOracle { | ||
using PendlePYOracleLib for IPMarket; | ||
using PendleLpOracleLib for IPMarket; | ||
|
||
IStandardizedYield public SY; | ||
IPPrincipalToken public PT; | ||
IPYieldToken public YT; | ||
|
||
IPMarket public market; | ||
PendlePYLpOracle public oracle; | ||
|
||
uint32 public twapDuration; | ||
|
||
string public symbol; | ||
|
||
constructor(address _market, address _oracle, uint32 _twapDuration) { | ||
require(_market != address(0) && _oracle != address(0), 'Invalid address'); | ||
require(twapDuration != 0, 'Invalid TWAP duration'); | ||
|
||
market = IPMarket(_market); | ||
oracle = PendlePYLpOracle(_oracle); | ||
twapDuration = _twapDuration; | ||
|
||
(SY, PT, YT) = market.readTokens(); | ||
|
||
// test if oracle is ready | ||
(bool increaseCardinalityRequired,, bool oldestObservationSatisfied) = oracle.getOracleState(_market, _twapDuration); | ||
// It's required to call IPMarket(market).increaseObservationsCardinalityNext(cardinalityRequired) and wait | ||
// for at least the twapDuration, to allow data population. | ||
// also | ||
// It's necessary to wait for at least the twapDuration, to allow data population. | ||
require(!increaseCardinalityRequired && oldestObservationSatisfied, 'Oracle not ready'); | ||
symbol = string(abi.encodePacked(IERC20Metadata(_market).symbol())); | ||
} | ||
// | ||
|
||
function getResultWithValidity() external view returns (uint256 _result, bool _validity) { | ||
_result = oracle.getPtToSyRate(address(market), twapDuration); | ||
|
||
//TODO check valid TWAP duration | ||
_validity = true; | ||
} | ||
|
||
// returns value of PT denominated in SY(underlying asset) | ||
|
||
function read() external view returns (uint256 _value) { | ||
_value = oracle.getPtToSyRate(address(market), twapDuration); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity ^0.8.17; | ||
|
||
interface IPMarket { | ||
function | ||
} |
Empty file.