Skip to content

Commit d802781

Browse files
quangloc99UncleGrandpa925
authored andcommitted
Add example that uses Oracle Library
1 parent 642b1ab commit d802781

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

test/OracleSample.sol

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ contract OracleSample is PRBTest, StdCheats, StructGen {
3535
_test_oracle_ready(address(market), twapDuration);
3636
}
3737

38+
////////////////
39+
//// Using Oracle
40+
////////////////
41+
3842
function test_get_price_LRT_in_underlying() external view {
3943
uint256 ptRateInWeEth = oracle.getPtToSyRate(address(market), twapDuration);
4044
uint256 ytRateInWeEth = oracle.getYtToSyRate(address(market), twapDuration);
@@ -65,9 +69,28 @@ contract OracleSample is PRBTest, StdCheats, StructGen {
6569
console.log("1 PT = %s USD (base 1e18)", ptRateInUsd);
6670
}
6771

68-
// ! Replace oracle.getPtToAssetRate to IPMarket(market).getPtToAssetRate to save 3000 gas
69-
function test_get_price_save_gas() external view {
72+
////////////////
73+
//// Using Lib
74+
////////////////
75+
76+
function test_get_price_LRT_in_underlying_with_lib() external view {
7077
uint256 ptRateInWeEth = market.getPtToSyRate(twapDuration);
78+
uint256 ytRateInWeEth = market.getYtToSyRate(twapDuration);
79+
uint256 lpRateInWeEth = market.getLpToSyRate(twapDuration);
80+
81+
console.log("1 PT = %s Wrapped eEth (base 1e18)", ptRateInWeEth);
82+
console.log("1 YT = %s Wrapped eEth (base 1e18)", ytRateInWeEth);
83+
console.log("1 LP = %s Wrapped eEth (base 1e18)", lpRateInWeEth);
84+
}
85+
86+
function test_get_price_LRT_with_external_oracle_with_lib() external view {
87+
uint256 ptRateInWeEth = market.getPtToSyRate(twapDuration); // 1 SY-weETH = 1 weETH
88+
89+
uint256 ptRateInEth = (ptRateInWeEth * uint256(weETH_ETH_feed.latestAnswer())) / (10 ** weETH_ETH_feed.decimals());
90+
console.log("1 PT = %s ETH (base 1e18)", ptRateInEth); // 1 PT = 0.980103943942239852 ETH
91+
92+
uint256 ptRateInUsd = (ptRateInEth * uint256(ETH_USD_feed.latestAnswer())) / (10 ** ETH_USD_feed.decimals());
93+
console.log("1 PT = %s USD (base 1e18)", ptRateInUsd); // 1 PT = 3714.1302603652102 USD
7194
}
7295

7396
/// @dev Call only once for each (market, duration). Once successful, it's permanently valid (also for any shorter

0 commit comments

Comments
 (0)