Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: deploy-oracle-PT-Dec-maturity #257

Merged
merged 10 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions contracts/oracle/morpho/mainnet/MorphoFeedPTweETHDec24.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.12;

import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";

import "../../BaseFeedPTPendle.sol";

/// @title MorphoFeedPTweETH
/// @author Angle Labs, Inc.
/// @notice Gives the price of PT-weETH in ETH in base 18
contract MorphoFeedPTweETHDec24 is BaseFeedPTPendle {
string public constant description = "PT-weETH/weETH Oracle";

Check warning on line 13 in contracts/oracle/morpho/mainnet/MorphoFeedPTweETHDec24.sol

View workflow job for this annotation

GitHub Actions / lint

Constant name must be in capitalized SNAKE_CASE

constructor(
IAccessControlManager accessControlManager,

Check notice

Code scanning / Slither

Local variable shadowing Low

uint256 _maxImpliedRate,
uint32 _twapDuration
) BaseFeedPTPendle(accessControlManager, _maxImpliedRate, _twapDuration) {}

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

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

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

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

function market() public pure override returns (address) {
return 0x7d372819240D14fB477f17b964f95F33BeB4c704;
}
}
2 changes: 1 addition & 1 deletion lib/utils
8 changes: 4 additions & 4 deletions scripts/foundry/mainnet/PTweETHOracle.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.17;

import "forge-std/Script.sol";
import { console } from "forge-std/console.sol";
import { MorphoFeedPTweETH } from "borrow-contracts/oracle/morpho/mainnet/MorphoFeedPTweETH.sol";
import { MorphoFeedPTweETHDec24 } from "borrow-contracts/oracle/morpho/mainnet/MorphoFeedPTweETHDec24.sol";
import "utils/src/CommonUtils.sol";
import { IAccessControlManager } from "borrow-contracts/interfaces/IAccessControlManager.sol";

Expand All @@ -15,12 +15,12 @@ contract PTweETHOracleDeploy is Script, CommonUtils {

// TODO
uint256 chainId = CHAIN_ETHEREUM;
address coreBorrow = 0x5bc6BEf80DA563EBf6Df6D6913513fa9A7ec89BE;
address coreBorrow = _chainToContract(chainId, ContractType.CoreBorrow);
uint32 _TWAP_DURATION = 30 minutes;
uint256 _MAX_IMPLIED_RATE = 0.5 ether;
uint256 _MAX_IMPLIED_RATE = 0.4 ether;
// end TODO

MorphoFeedPTweETH oracle = new MorphoFeedPTweETH(
MorphoFeedPTweETHDec24 oracle = new MorphoFeedPTweETHDec24(
IAccessControlManager(address(coreBorrow)),
_MAX_IMPLIED_RATE,
_TWAP_DURATION
Expand Down
3 changes: 0 additions & 3 deletions test/foundry/oracles/morpho/MorphoChainlinkOracleTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ import { PendlePtOracleLib } from "pendle/oracles/PendlePtOracleLib.sol";
contract MorphoChainlinkOracleTest is Test, CommonUtils {
using stdStorage for StdStorage;

mapping(uint256 => uint256) internal forkIdentifier;
uint256 public ethereumFork;

address internal _alice = address(uint160(uint256(keccak256(abi.encodePacked("alice")))));
address internal _governor = address(uint160(uint256(keccak256(abi.encodePacked("governor")))));
address internal _guardian = address(uint160(uint256(keccak256(abi.encodePacked("guardian")))));
Expand Down
1 change: 1 addition & 0 deletions test/foundry/oracles/pendle/MorphoFeedPTPendle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.12;
import { console } from "forge-std/console.sol";
import { stdStorage, StdStorage, Test } from "forge-std/Test.sol";
import { MorphoFeedPTweETH, BaseFeedPTPendle } from "borrow-contracts/oracle/morpho/mainnet/MorphoFeedPTweETH.sol";
import { MorphoFeedPTweETHDec24 } from "borrow-contracts/oracle/morpho/mainnet/MorphoFeedPTweETHDec24.sol";
import { MockTreasury } from "borrow-contracts/mock/MockTreasury.sol";
import { IAgToken } from "borrow-contracts/interfaces/IAgToken.sol";
import { IAccessControlManager } from "borrow-contracts/interfaces/IAccessControlManager.sol";
Expand Down
92 changes: 92 additions & 0 deletions test/foundry/oracles/pendle/MorphoFeedPTweETHDec24.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.12;

import "./MorphoFeedPTPendle.t.sol";
import { IAccessControlManager } from "borrow-contracts/interfaces/IAccessControlManager.sol";

contract MorphoFeedPTweETHDec24Test is MorphoFeedPTPendleTest {
using stdStorage for StdStorage;

function setUp() public override {
super.setUp();

_TWAP_DURATION = 30 minutes;
_STALE_PERIOD = 24 hours;
_MAX_IMPLIED_RATE = 0.4 ether;

_oracle = new MorphoFeedPTweETHDec24(
IAccessControlManager(address(coreBorrow)),
_MAX_IMPLIED_RATE,
_TWAP_DURATION
);
}

/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CORE LOGIC
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

function test_Description_Success() public {
assertEq(_oracle.description(), "PT-weETH/weETH Oracle");
}

function test_Simple_Success() public {
(, int256 answer, , , ) = _oracle.latestRoundData();
uint256 value = uint256(answer);

assertApproxEqAbs(value, 0.8 ether, 0.01 ether);
}

function test_EconomicalLowerBound_tooSmall() public {
vm.prank(_governor);
_oracle.setMaxImpliedRate(uint256(1e1));
uint256 pendleAMMPrice = PendlePtOracleLib.getPtToAssetRate(IPMarket(_oracle.market()), _TWAP_DURATION);

(, int256 answer, , , ) = _oracle.latestRoundData();
uint256 value = uint256(answer);

assertEq(value, pendleAMMPrice);
}

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

uint256 pendleAMMPrice = PendlePtOracleLib.getPtToAssetRate(IPMarket(_oracle.market()), _TWAP_DURATION);
(, int256 answer, , , ) = _oracle.latestRoundData();
uint256 value = uint256(answer);

assertEq(value, pendleAMMPrice);
assertEq(value, 1 ether);
}

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());
uint256 postBalance = (prevBalance * slash) / BASE_18;
deal(address(weETH), _oracle.sy(), postBalance);

uint256 lowerBound = _economicLowerBound(_MAX_IMPLIED_RATE, _oracle.maturity());
(, int256 answer, , , ) = _oracle.latestRoundData();
uint256 value = uint256(answer);

assertLe(value, (lowerBound * slash) / BASE_18);
if (slash > 0) assertGe(value, (lowerBound * (slash - 1)) / BASE_18);
}

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());
uint256 postBalance = (prevBalance * expand) / BASE_18;
deal(address(weETH), _oracle.sy(), postBalance);

uint256 lowerBound = _economicLowerBound(_MAX_IMPLIED_RATE, _oracle.maturity());
(, int256 answer, , , ) = _oracle.latestRoundData();
uint256 value = uint256(answer);

assertEq(value, lowerBound);
}
}
Loading