Skip to content

Commit

Permalink
added missing files
Browse files Browse the repository at this point in the history
  • Loading branch information
MrDeadCe11 committed Jul 3, 2024
1 parent d458630 commit 1dcb0dd
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
63 changes: 63 additions & 0 deletions src/contracts/oracles/PendlePTRelayer.sol
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);
}
}
6 changes: 6 additions & 0 deletions src/interfaces/pendle/IPMarket.sol
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.

0 comments on commit 1dcb0dd

Please sign in to comment.