Skip to content

Commit

Permalink
Add Chainlink test
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleGrandpa925 committed Nov 15, 2024
1 parent d92e20b commit 76d8925
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 1 deletion.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"forge-std": "github:foundry-rs/forge-std#v1.7.5",
"prettier": "^3.0.0",
"solhint": "^3.6.2",
"@pendle/core-v2": "^4.7.0"
"@pendle/core-v2": "^5.2.0-beta-2"
},
"keywords": [
"blockchain",
Expand Down
96 changes: 96 additions & 0 deletions test/ChainlinkOracleSample.sol
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
}
}

0 comments on commit 76d8925

Please sign in to comment.