Skip to content

Commit

Permalink
fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeNervoXS committed Feb 27, 2024
1 parent 1e07b90 commit 0b9bbb3
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 37 deletions.
18 changes: 9 additions & 9 deletions contracts/oracle/BaseOraclePTPendle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pragma solidity ^0.8.12;

import { UNIT, UD60x18, ud, intoUint256 } from "prb/math/UD60x18.sol";
import { UNIT, UD60x18, ud } from "prb/math/UD60x18.sol";
import "pendle/interfaces/IPMarket.sol";
import { PendlePtOracleLib } from "pendle/oracles/PendlePtOracleLib.sol";
import "../interfaces/ITreasury.sol";
Expand Down Expand Up @@ -58,7 +58,7 @@ abstract contract BaseOraclePTPendle {
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

function _economicalPTLowerBoundPrice() internal view returns (uint256) {
uint256 exp = block.timestamp > MATURITY() ? 0 : MATURITY() - block.timestamp;
uint256 exp = block.timestamp > maturity() ? 0 : maturity() - block.timestamp;
if (exp == 0) return BASE_18;

UD60x18 denominator = UNIT.add(ud(maxImpliedRate)).pow(ud(exp).div(ud(YEAR)));
Expand All @@ -67,26 +67,26 @@ abstract contract BaseOraclePTPendle {
}

function _pendlePTPrice() internal view returns (uint256) {
return PendlePtOracleLib.getPtToAssetRate(IPMarket(MARKET()), twapDuration);
return PendlePtOracleLib.getPtToAssetRate(IPMarket(market()), twapDuration);
}

function _detectHackRatio() internal view returns (uint256) {
uint256 assetBalanceSY = IERC20(ASSET()).balanceOf(SY());
uint256 totalSupplySY = IERC20(SY()).totalSupply();
uint256 assetBalanceSY = IERC20(asset()).balanceOf(sy());
uint256 totalSupplySY = IERC20(sy()).totalSupply();
return assetBalanceSY > totalSupplySY ? BASE_18 : (assetBalanceSY * BASE_18) / totalSupplySY;
}

/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
OVERRIDES
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

function ASSET() public pure virtual returns (address);
function asset() public pure virtual returns (address);

function SY() public pure virtual returns (address);
function sy() public pure virtual returns (address);

function MATURITY() public pure virtual returns (uint256);
function maturity() public pure virtual returns (uint256);

function MARKET() public pure virtual returns (address);
function market() public pure virtual returns (address);

function _onlyGovernorOrGuardian() internal view virtual;
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ contract OraclePTweETHEUR is BaseOracleChainlinkMultiTwoFeeds, BaseOraclePTPendl
OVERRIDES
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

function ASSET() public pure override returns (address) {
function asset() public pure override returns (address) {
return 0xCd5fE23C85820F7B72D0926FC9b05b43E359b7ee;
}

function SY() public pure override returns (address) {
function sy() public pure override returns (address) {
return 0xAC0047886a985071476a1186bE89222659970d65;
}

function MATURITY() public pure override returns (uint256) {
function maturity() public pure override returns (uint256) {
return 1719446400;
}

function MARKET() public pure override returns (address) {
function market() public pure override returns (address) {
return 0xF32e58F92e60f4b0A37A69b95d642A471365EAe8;
}

Expand Down
1 change: 0 additions & 1 deletion lib/abdk-libraries-solidity
Submodule abdk-libraries-solidity deleted from 5e1e7c
24 changes: 12 additions & 12 deletions test/foundry/oracles/pendle/BaseOraclePendlePT.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ contract BaseOraclePendlePT is Test {

contract BaseOraclePendlePTTest is BaseOraclePendlePT {
using stdStorage for StdStorage;

/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
SETTERS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
Expand Down Expand Up @@ -189,19 +190,19 @@ contract BaseOraclePendlePTTest is BaseOraclePendlePT {
function test_EconomicalLowerBound_tooSmall() public {
vm.prank(_governor);
_oracle.setMaxImpliedRate(uint256(1e1));
uint256 pendleAMMPrice = PendlePtOracleLib.getPtToAssetRate(IPMarket(_oracle.MARKET()), _TWAP_DURATION);
uint256 pendleAMMPrice = PendlePtOracleLib.getPtToAssetRate(IPMarket(_oracle.market()), _TWAP_DURATION);

assertEq(_oracle.read(), _read(pendleAMMPrice));
}

function test_AfterMaturity_Success() public {
// Adavnce to the PT maturity
vm.warp(_oracle.MATURITY());
vm.warp(_oracle.maturity());

// Update the last timestamp oracle push
_updateChainlinkTimestamp(block.timestamp);

uint256 pendleAMMPrice = PendlePtOracleLib.getPtToAssetRate(IPMarket(_oracle.MARKET()), _TWAP_DURATION);
uint256 pendleAMMPrice = PendlePtOracleLib.getPtToAssetRate(IPMarket(_oracle.market()), _TWAP_DURATION);
uint256 value = _oracle.read();
assertEq(value, _read(pendleAMMPrice));
assertEq(value, _read(1 ether));
Expand All @@ -210,12 +211,12 @@ contract BaseOraclePendlePTTest is BaseOraclePendlePT {
function test_HackRemove_Success(uint256 slash) public {
slash = bound(slash, 1, BASE_18);
// Remove part of the SY backing collateral to simulate a hack
IERC20 weETH = IERC20(address(_oracle.ASSET()));
uint256 prevBalance = weETH.balanceOf(_oracle.SY());
IERC20 weETH = IERC20(address(_oracle.asset()));
uint256 prevBalance = weETH.balanceOf(_oracle.sy());
uint256 postBalance = (prevBalance * slash) / BASE_18;
deal(address(weETH), _oracle.SY(), postBalance);
deal(address(weETH), _oracle.sy(), postBalance);

uint256 lowerBound = _economicLowerBound(_MAX_IMPLIED_RATE, _oracle.MATURITY());
uint256 lowerBound = _economicLowerBound(_MAX_IMPLIED_RATE, _oracle.maturity());
uint256 value = _oracle.read();

assertLe(value, _read((lowerBound * slash) / BASE_18));
Expand All @@ -225,15 +226,14 @@ contract BaseOraclePendlePTTest is BaseOraclePendlePT {
function test_HackExpand_Success(uint256 expand) public {
expand = bound(expand, BASE_18, BASE_18 * 1e7);
// Remove part of the SY backing collateral to simulate a hack
IERC20 weETH = IERC20(address(_oracle.ASSET()));
uint256 prevBalance = weETH.balanceOf(_oracle.SY());
IERC20 weETH = IERC20(address(_oracle.asset()));
uint256 prevBalance = weETH.balanceOf(_oracle.sy());
uint256 postBalance = (prevBalance * expand) / BASE_18;
deal(address(weETH), _oracle.SY(), postBalance);
deal(address(weETH), _oracle.sy(), postBalance);

uint256 lowerBound = _economicLowerBound(_MAX_IMPLIED_RATE, _oracle.MATURITY());
uint256 lowerBound = _economicLowerBound(_MAX_IMPLIED_RATE, _oracle.maturity());
uint256 value = _oracle.read();

assertEq(value, _read((lowerBound)));
}
}

22 changes: 11 additions & 11 deletions test/foundry/oracles/pendle/OraclePTweETH.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ contract OraclePTweETH is BaseOraclePendlePT {
function test_EconomicalLowerBound_tooSmall() public {
vm.prank(_governor);
_oracle.setMaxImpliedRate(uint256(1e1));
uint256 pendleAMMPrice = PendlePtOracleLib.getPtToAssetRate(IPMarket(_oracle.MARKET()), _TWAP_DURATION);
uint256 pendleAMMPrice = PendlePtOracleLib.getPtToAssetRate(IPMarket(_oracle.market()), _TWAP_DURATION);

assertEq(_oracle.read(), _read(pendleAMMPrice));
}

function test_AfterMaturity_Success() public {
// Adavnce to the PT maturity
vm.warp(_oracle.MATURITY());
vm.warp(_oracle.maturity());

// Update the last timestamp oracle push
_updateChainlinkTimestamp(block.timestamp);

uint256 pendleAMMPrice = PendlePtOracleLib.getPtToAssetRate(IPMarket(_oracle.MARKET()), _TWAP_DURATION);
uint256 pendleAMMPrice = PendlePtOracleLib.getPtToAssetRate(IPMarket(_oracle.market()), _TWAP_DURATION);
uint256 value = _oracle.read();
assertEq(value, _read(pendleAMMPrice));
assertEq(value, _read(1 ether));
Expand All @@ -57,12 +57,12 @@ contract OraclePTweETH is BaseOraclePendlePT {
function test_HackRemove_Success(uint256 slash) public {
slash = bound(slash, 1, BASE_18);
// Remove part of the SY backing collateral to simulate a hack
IERC20 weETH = IERC20(address(_oracle.ASSET()));
uint256 prevBalance = weETH.balanceOf(_oracle.SY());
IERC20 weETH = IERC20(address(_oracle.asset()));
uint256 prevBalance = weETH.balanceOf(_oracle.sy());
uint256 postBalance = (prevBalance * slash) / BASE_18;
deal(address(weETH), _oracle.SY(), postBalance);
deal(address(weETH), _oracle.sy(), postBalance);

uint256 lowerBound = _economicLowerBound(_MAX_IMPLIED_RATE, _oracle.MATURITY());
uint256 lowerBound = _economicLowerBound(_MAX_IMPLIED_RATE, _oracle.maturity());
uint256 value = _oracle.read();

assertLe(value, _read((lowerBound * slash) / BASE_18));
Expand All @@ -72,12 +72,12 @@ contract OraclePTweETH is BaseOraclePendlePT {
function test_HackExpand_Success(uint256 expand) public {
expand = bound(expand, BASE_18, BASE_18 * 1e7);
// Remove part of the SY backing collateral to simulate a hack
IERC20 weETH = IERC20(address(_oracle.ASSET()));
uint256 prevBalance = weETH.balanceOf(_oracle.SY());
IERC20 weETH = IERC20(address(_oracle.asset()));
uint256 prevBalance = weETH.balanceOf(_oracle.sy());
uint256 postBalance = (prevBalance * expand) / BASE_18;
deal(address(weETH), _oracle.SY(), postBalance);
deal(address(weETH), _oracle.sy(), postBalance);

uint256 lowerBound = _economicLowerBound(_MAX_IMPLIED_RATE, _oracle.MATURITY());
uint256 lowerBound = _economicLowerBound(_MAX_IMPLIED_RATE, _oracle.maturity());
uint256 value = _oracle.read();

assertEq(value, _read((lowerBound)));
Expand Down

0 comments on commit 0b9bbb3

Please sign in to comment.