Skip to content

Commit

Permalink
feat: OjoPTOraclePriceAdapter
Browse files Browse the repository at this point in the history
  • Loading branch information
rbajollari committed Nov 26, 2024
1 parent 26a475c commit 7a31d2e
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,11 @@ ETH_RPC_URL=
HOLESKY_RPC_URL=
ETHERSCAN_API_KEY=

# OjoPendleOracle
PT_ADDRESS=
BASE_DISCOUNT_PER_YEAR=

# OjoPTOraclePriceAdapter
PT_ORACLE=
MARKET=
DESCRIPTION=
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cache/
out/

# Ignores development broadcast logs
!/broadcast
broadcast
/broadcast/*/31337/
/broadcast/**/dry-run/

Expand Down
17 changes: 17 additions & 0 deletions script/OjoPendleOracle.s.sol → script/OjoPendleOracles.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity 0.8.19;

import {Script} from "forge-std/Script.sol";
import {OjoPendleOracle} from "src/OjoPendleOracle.sol";
import {OjoPTOraclePriceAdapter} from "src/OjoPTOraclePriceAdapter.sol";
import {console} from "forge-std/console.sol";

contract DeployOjoPendleOracle is Script {
Expand All @@ -19,3 +20,19 @@ contract DeployOjoPendleOracle is Script {
console.log("OjoPendleOracle Address:", address(ojoPendleOracle));
}
}

contract DeployOjoPTOraclePriceAdapter is Script {
function run() external {
address _ptoracle = vm.envAddress("PT_ORACLE");
address _market = vm.envAddress("MARKET");
string memory _description = vm.envString("DESCRIPTION");

vm.startBroadcast();

OjoPTOraclePriceAdapter ojoPTOraclePriceAdapter = new OjoPTOraclePriceAdapter(_ptoracle, _market, _description);

vm.stopBroadcast();

console.log("OjoPTOraclePriceAdapter Address:", address(ojoPTOraclePriceAdapter));
}
}
38 changes: 38 additions & 0 deletions src/OjoPTOraclePriceAdapter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.8.19;

import {IPTOracle} from "./interfaces/IPTOracle.sol";
import {MinimalAggregatorV3Interface} from "./interfaces/MinimalAggregatorV3Interface.sol";

contract OjoPTOraclePriceAdapter is MinimalAggregatorV3Interface {
uint8 public constant decimals = 18;

address public immutable PTOracle;

address public immutable market;

string public description;

constructor(address _ptoracle, address _market, string memory _description) {
require(_ptoracle != address(0), "_ptoracle zero address");
require(_market != address(0), "_market zero address");

PTOracle = _ptoracle;
market = _market;
description = _description;
}

/// @inheritdoc MinimalAggregatorV3Interface
/// @dev Returns zero for roundId, startedAt, updatedAt and answeredInRound.
/// @dev Silently overflows if `price`'s average is greater than `type(int256).max`.
function latestRoundData() external view returns (uint80, int256, uint256, uint256, uint80) {
IPTOracle oracle = IPTOracle(PTOracle);

uint256 price = oracle.getPtToAssetRate(
market,
900 // 15 mins twap duration
);

return (0, int256(price), 0, 0, 0);
}
}
6 changes: 6 additions & 0 deletions src/interfaces/IPTOracle.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

interface IPTOracle {
function getPtToAssetRate(address market, uint32 duration) external view returns (uint256);
}
17 changes: 17 additions & 0 deletions src/interfaces/MinimalAggregatorV3Interface.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.5.0;

/// @dev Inspired by
/// https://github.com/smartcontractkit/chainlink/blob/master/contracts/src/v0.8/shared/interfaces/AggregatorV3Interface.sol
/// @dev This is the minimal feed interface required by `MorphoChainlinkOracleV2`.
interface MinimalAggregatorV3Interface {
/// @notice Returns the precision of the feed.
function decimals() external view returns (uint8);

/// @notice Returns Chainlink's `latestRoundData` return values.
/// @notice Only the `answer` field is used by `MorphoChainlinkOracleV2`.
function latestRoundData()
external
view
returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);
}

0 comments on commit 7a31d2e

Please sign in to comment.