-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
d92e20b
commit 76d8925
Showing
3 changed files
with
97 additions
and
1 deletion.
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
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,96 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity >=0.8.23 <0.9.0; | ||
|
||
import { PRBTest } from "@prb/test/src/PRBTest.sol"; | ||
import { console2 as console } from "forge-std/src/console2.sol"; | ||
import { StdCheats } from "forge-std/src/StdCheats.sol"; | ||
import "@pendle/core-v2/contracts/interfaces/IPAllActionV3.sol"; | ||
import "@pendle/core-v2/contracts/interfaces/IPMarket.sol"; | ||
import "@pendle/core-v2/contracts/oracles/PendlePYLpOracle.sol"; | ||
import "../src/StructGen.sol"; | ||
import { AggregatorV2V3Interface as IChainlinkAggregator } from "@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol"; | ||
import "@pendle/core-v2/contracts/oracles/factory/PendleChainlinkOracleFactory.sol"; | ||
import "@pendle/core-v2/contracts/oracles/factory/PendleChainlinkOracle.sol"; | ||
|
||
contract ChainlinkOracleSample is PRBTest, StdCheats, StructGen { | ||
using PendlePYOracleLib for IPMarket; | ||
using PendleLpOracleLib for IPMarket; | ||
|
||
IStandardizedYield public SY; | ||
IPPrincipalToken public PT; | ||
IPYieldToken public YT; | ||
|
||
IPMarket public constant market = IPMarket(0x952083cde7aaa11AB8449057F7de23A970AA8472); | ||
PendleChainlinkOracleFactory public factory; | ||
PendleChainlinkOracle public PTweETH_weETH_oracle; | ||
PendleChainlinkOracle public YTweETH_weETH_oracle; | ||
PendleChainlinkOracle public LPweETH_weETH_oracle; | ||
PendleChainlinkOracleWithQuote public PTweETH_ETH_oracle; | ||
PendleChainlinkOracleWithQuote public YTweETH_ETH_oracle; | ||
PendleChainlinkOracleWithQuote public LPweETH_ETH_oracle; | ||
|
||
IChainlinkAggregator public constant weETH_ETH_feed = | ||
IChainlinkAggregator(0xE141425bc1594b8039De6390db1cDaf4397EA22b); | ||
|
||
uint16 public constant twapDuration = 900; | ||
|
||
function setUp() public virtual { | ||
vm.createSelectFork({ urlOrAlias: "arbitrum", blockNumber: 218241893 }); | ||
(SY, PT, YT) = IPMarket(market).readTokens(); | ||
factory = new PendleChainlinkOracleFactory(0x9a9Fa8338dd5E5B2188006f1Cd2Ef26d921650C2); | ||
PTweETH_weETH_oracle = PendleChainlinkOracle( | ||
factory.createOracle(address(market), twapDuration, PendleOracleType.PT_TO_SY) | ||
); | ||
YTweETH_weETH_oracle = PendleChainlinkOracle( | ||
factory.createOracle(address(market), twapDuration, PendleOracleType.YT_TO_SY) | ||
); | ||
LPweETH_weETH_oracle = PendleChainlinkOracle( | ||
factory.createOracle(address(market), twapDuration, PendleOracleType.LP_TO_SY) | ||
); | ||
|
||
PTweETH_ETH_oracle = PendleChainlinkOracleWithQuote( | ||
factory.createOracleWithQuote(address(market), twapDuration, PendleOracleType.PT_TO_SY, address(weETH_ETH_feed)) | ||
); | ||
YTweETH_ETH_oracle = PendleChainlinkOracleWithQuote( | ||
factory.createOracleWithQuote(address(market), twapDuration, PendleOracleType.YT_TO_SY, address(weETH_ETH_feed)) | ||
); | ||
LPweETH_ETH_oracle = PendleChainlinkOracleWithQuote( | ||
factory.createOracleWithQuote(address(market), twapDuration, PendleOracleType.LP_TO_SY, address(weETH_ETH_feed)) | ||
); | ||
} | ||
|
||
function test_get_prices_in_SY() external view { | ||
(uint80 roundId, int256 answer, , uint256 updatedAt, uint80 answeredInRound) = PTweETH_weETH_oracle | ||
.latestRoundData(); | ||
console.log("PT weETH to SY-weETH"); | ||
console.log(uint256(roundId), uint256(answer), updatedAt, uint256(answeredInRound)); | ||
// answer = 950178386279542590, meaning 1 PT = 0.950178386279542590 SY-weETH | ||
|
||
(roundId, answer, , updatedAt, answeredInRound) = YTweETH_weETH_oracle.latestRoundData(); | ||
console.log("YT weETH to SY-weETH"); | ||
console.log(uint256(roundId), uint256(answer), updatedAt, uint256(answeredInRound)); | ||
// answer = 11456164742132575, meaning 1 YT = 0.011456164742132575 SY-weETH | ||
|
||
(roundId, answer, , updatedAt, answeredInRound) = LPweETH_weETH_oracle.latestRoundData(); | ||
console.log("LP weETH to SY-weETH"); | ||
console.log(uint256(roundId), uint256(answer), updatedAt, uint256(answeredInRound)); | ||
// answer = 1902647970497216309, meaning 1 LP = 1.902647970497216309 SY-weETH | ||
} | ||
|
||
function test_get_prices_in_quote() external view { | ||
(uint80 roundId, int256 answer, , uint256 updatedAt, uint80 answeredInRound) = PTweETH_ETH_oracle.latestRoundData(); | ||
console.log("PT weETH to ETH"); | ||
console.log(uint256(roundId), uint256(answer), updatedAt, uint256(answeredInRound)); | ||
// answer = 987284630840569599, meaning 1 PT = 0.987284630840569599 ETH | ||
|
||
(roundId, answer, , updatedAt, answeredInRound) = YTweETH_ETH_oracle.latestRoundData(); | ||
console.log("YT weETH to ETH"); | ||
console.log(uint256(roundId), uint256(answer), updatedAt, uint256(answeredInRound)); | ||
// answer = 11903549419358776, meaning 1 YT = 0.011903549419358776 ETH | ||
|
||
(roundId, answer, , updatedAt, answeredInRound) = LPweETH_ETH_oracle.latestRoundData(); | ||
console.log("LP weETH to ETH"); | ||
console.log(uint256(roundId), uint256(answer), updatedAt, uint256(answeredInRound)); | ||
// answer = 1976949935187497999, meaning 1 LP = 1.976949935187497999 ETH | ||
} | ||
} |