Skip to content

Commit

Permalink
Merge pull request #77 from Ion-Protocol/hrikb/C-01
Browse files Browse the repository at this point in the history
OZ: C-01
  • Loading branch information
HrikB authored May 6, 2024
2 parents c389c0b + d2d439e commit 82bd2cf
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/oracles/reserve/pendle/EzEthPtReserveOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ contract EzEthPtReserveOracle is ReserveOracle {
(,, uint256 totalTVL) = RENZO_RESTAKE_MANAGER.calculateTVLs();
uint256 totalSupply = EZETH.totalSupply();

return totalTVL.mulDiv(1e18, totalSupply);
return totalSupply.mulDiv(1e18, totalTVL);
}
}
7 changes: 6 additions & 1 deletion src/oracles/reserve/pendle/RsEthPtReserveOracle.sol
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;

import { WAD } from "../../../libraries/math/WadRayMath.sol";
import { RSETH_LRT_ORACLE } from "../../../Constants.sol";
import { ReserveOracle } from "../ReserveOracle.sol";

import { Math } from "@openzeppelin/contracts/utils/math/Math.sol";

/**
* @notice Reserve Oracle for PT-rsETH
*
* @custom:security-contact [email protected]
*/
contract RsEthPtReserveOracle is ReserveOracle {
using Math for uint256;

constructor(
uint8 _ilkIndex,
address[] memory _feeds,
Expand All @@ -24,6 +29,6 @@ contract RsEthPtReserveOracle is ReserveOracle {
* at maturity, we need to convert 1 ETH of value into rsETH terms.
*/
function _getProtocolExchangeRate() internal view override returns (uint256) {
return RSETH_LRT_ORACLE.rsETHPrice();
return WAD.mulDiv(WAD, RSETH_LRT_ORACLE.rsETHPrice());
}
}
34 changes: 34 additions & 0 deletions test/fork/concrete/pendle/PtReserveOracle.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;

import { Test } from "forge-std/Test.sol";
import { EzEthPtReserveOracle } from "../../../../src/oracles/reserve/pendle/EzEthPtReserveOracle.sol";
import { RsEthPtReserveOracle } from "../../../../src/oracles/reserve/pendle/RsEthPtReserveOracle.sol";
import { RswEthPtReserveOracle } from "../../../../src/oracles/reserve/pendle/RswEthPtReserveOracle.sol";
import { WeEthPtReserveOracle } from "../../../../src/oracles/reserve/pendle/WeEthPtReserveOracle.sol";

contract PtReserveOracleTest is Test {
function setUp() public {
vm.createSelectFork(vm.envString("MAINNET_RPC_URL"));
}

function test_WeEth() public {
WeEthPtReserveOracle reserveOracle = new WeEthPtReserveOracle(0, new address[](3), 0, 0.02e18);
assertLe(reserveOracle.getProtocolExchangeRate(), 1e18);
}

function test_RsEth() public {
RsEthPtReserveOracle reserveOracle = new RsEthPtReserveOracle(0, new address[](3), 0, 0.02e18);
assertLe(reserveOracle.getProtocolExchangeRate(), 1e18);
}

function test_RswEth() public {
RswEthPtReserveOracle reserveOracle = new RswEthPtReserveOracle(0, new address[](3), 0, 0.02e18);
assertLe(reserveOracle.getProtocolExchangeRate(), 1e18);
}

function test_EzEth() public {
EzEthPtReserveOracle reserveOracle = new EzEthPtReserveOracle(0, new address[](3), 0, 0.02e18);
assertLe(reserveOracle.getProtocolExchangeRate(), 1e18);
}
}

0 comments on commit 82bd2cf

Please sign in to comment.