From 4537fbd4517bd1c7336aef9c5f16473ca7691afc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment?= Date: Wed, 6 Nov 2024 22:01:14 +0700 Subject: [PATCH 1/8] feat: use ERC4626FiatCollateral dependency. --- .../plugins/assets/origin/OETHCollateralL2Base.sol | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/contracts/plugins/assets/origin/OETHCollateralL2Base.sol b/contracts/plugins/assets/origin/OETHCollateralL2Base.sol index d597b2b09..4b370718a 100644 --- a/contracts/plugins/assets/origin/OETHCollateralL2Base.sol +++ b/contracts/plugins/assets/origin/OETHCollateralL2Base.sol @@ -3,7 +3,7 @@ pragma solidity 0.8.19; import "@openzeppelin/contracts/utils/math/Math.sol"; import "../../../libraries/Fixed.sol"; -import "../AppreciatingFiatCollateral.sol"; +import "../ERC4626FiatCollateral.sol"; import "../OracleLib.sol"; interface IWSuperOETHb { @@ -114,7 +114,7 @@ interface IMorphoChainlinkOracleV2 { * tar = ETH * UoA = USD */ -contract OETHCollateralL2Base is AppreciatingFiatCollateral { +contract OETHCollateralL2Base is ERC4626FiatCollateral { using OracleLib for AggregatorV3Interface; using FixLib for uint192; @@ -132,7 +132,7 @@ contract OETHCollateralL2Base is AppreciatingFiatCollateral { IMorphoChainlinkOracleV2 _targetPerTokChainlinkFeed, AggregatorV3Interface _uoaPerTargetChainlinkFeed, uint48 _uoaPerTargetChainlinkTimeout - ) AppreciatingFiatCollateral(config, revenueHiding) { + ) ERC4626FiatCollateral(config, revenueHiding) { require(config.defaultThreshold != 0, "defaultThreshold zero"); require(address(_targetPerTokChainlinkFeed) != address(0), "targetPerTokFeed missing"); @@ -181,10 +181,4 @@ contract OETHCollateralL2Base is AppreciatingFiatCollateral { // ETH/superOETHb = ETH/wsuperOETHb / superOETHb/wsuperOETHb pegPrice = targetPerTok.div(underlyingRefPerTok()); } - - /// @return {ref/tok} Quantity of whole reference units per whole collateral tokens - /// {superOETHb/wsuperOETHb} - function underlyingRefPerTok() public view override returns (uint192) { - return _safeWrap(IWSuperOETHb(address(erc20)).convertToAssets(FIX_ONE)); - } } From 30b7f18924339f17a464ffd3b411440230d83a62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment?= Date: Wed, 6 Nov 2024 22:03:29 +0700 Subject: [PATCH 2/8] fix: avoid overflow risk. --- .../assets/origin/OETHCollateralL2Base.sol | 42 ++++--------------- 1 file changed, 7 insertions(+), 35 deletions(-) diff --git a/contracts/plugins/assets/origin/OETHCollateralL2Base.sol b/contracts/plugins/assets/origin/OETHCollateralL2Base.sol index 4b370718a..450687705 100644 --- a/contracts/plugins/assets/origin/OETHCollateralL2Base.sol +++ b/contracts/plugins/assets/origin/OETHCollateralL2Base.sol @@ -10,17 +10,10 @@ interface IWSuperOETHb { event Approval(address indexed owner, address indexed spender, uint256 value); event Deposit(address indexed caller, address indexed owner, uint256 assets, uint256 shares); event GovernorshipTransferred(address indexed previousGovernor, address indexed newGovernor); - event PendingGovernorshipTransfer( - address indexed previousGovernor, - address indexed newGovernor - ); + event PendingGovernorshipTransfer(address indexed previousGovernor, address indexed newGovernor); event Transfer(address indexed from, address indexed to, uint256 value); event Withdraw( - address indexed caller, - address indexed receiver, - address indexed owner, - uint256 assets, - uint256 shares + address indexed caller, address indexed receiver, address indexed owner, uint256 assets, uint256 shares ); function allowance(address owner, address spender) external view returns (uint256); @@ -71,11 +64,7 @@ interface IWSuperOETHb { function previewWithdraw(uint256 assets) external view returns (uint256); - function redeem( - uint256 shares, - address receiver, - address owner - ) external returns (uint256); + function redeem(uint256 shares, address receiver, address owner) external returns (uint256); function symbol() external view returns (string memory); @@ -85,21 +74,13 @@ interface IWSuperOETHb { function transfer(address recipient, uint256 amount) external returns (bool); - function transferFrom( - address sender, - address recipient, - uint256 amount - ) external returns (bool); + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); function transferGovernance(address _newGovernor) external; function transferToken(address asset_, uint256 amount_) external; - function withdraw( - uint256 assets, - address receiver, - address owner - ) external returns (uint256); + function withdraw(uint256 assets, address receiver, address owner) external returns (uint256); } interface IMorphoChainlinkOracleV2 { @@ -150,19 +131,10 @@ contract OETHCollateralL2Base is ERC4626FiatCollateral { /// @return low {UoA/tok} The low price estimate /// @return high {UoA/tok} The high price estimate /// @return pegPrice {target/ref} The actual price observed in the peg - function tryPrice() - external - view - override - returns ( - uint192 low, - uint192 high, - uint192 pegPrice - ) - { + function tryPrice() external view override returns (uint192 low, uint192 high, uint192 pegPrice) { // {tar/tok} // {ETH/wsuperOETHb} - uint192 targetPerTok = _safeWrap(targetPerTokChainlinkFeed.price()) / 1e18; + uint192 targetPerTok = _safeWrap(targetPerTokChainlinkFeed.price() / FIX_ONE); // {UoA/tar} // {USD/ETH} From 50784cfa2164a72e120f9581e166665a6b7e3639 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment?= Date: Wed, 6 Nov 2024 22:05:36 +0700 Subject: [PATCH 3/8] fix: remove comment. --- contracts/plugins/assets/origin/OETHCollateralL2Base.sol | 1 - 1 file changed, 1 deletion(-) diff --git a/contracts/plugins/assets/origin/OETHCollateralL2Base.sol b/contracts/plugins/assets/origin/OETHCollateralL2Base.sol index 450687705..bfe939c40 100644 --- a/contracts/plugins/assets/origin/OETHCollateralL2Base.sol +++ b/contracts/plugins/assets/origin/OETHCollateralL2Base.sol @@ -106,7 +106,6 @@ contract OETHCollateralL2Base is ERC4626FiatCollateral { /// @param config.chainlinkFeed - ignored /// @param config.oracleTimeout - ignored - /// @param config.oracleError {1} Should be the oracle error for UoA/tok constructor( CollateralConfig memory config, uint192 revenueHiding, From c783c1199ee2d0f7d47d37c3cfc160b47487c8dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment?= Date: Wed, 6 Nov 2024 22:12:58 +0700 Subject: [PATCH 4/8] fix: oracle error. --- test/plugins/individual-collateral/origin/constants.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/plugins/individual-collateral/origin/constants.ts b/test/plugins/individual-collateral/origin/constants.ts index bdeb9a1f2..0225214a7 100644 --- a/test/plugins/individual-collateral/origin/constants.ts +++ b/test/plugins/individual-collateral/origin/constants.ts @@ -17,10 +17,8 @@ export const BASE_FEEDS_TIMEOUT = { wsuperOETHb_ETH: bn(86400), ETH_USD: bn(1200), } -export const BASE_ORACLE_ERROR = combinedError( - fp('0.0015'), - combinedError(fp('0.005'), fp('0.005')) -) +export const BASE_ORACLE_ERROR = combinedError(fp('0.005'), fp('0.015')) + // Data export const PRICE_TIMEOUT = bn('604800') // 1 week From 648124973201d78dd128fa01ae7368a7622eef8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment?= Date: Wed, 6 Nov 2024 22:45:57 +0700 Subject: [PATCH 5/8] prettier --- .../assets/origin/OETHCollateralL2Base.sol | 40 ++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/contracts/plugins/assets/origin/OETHCollateralL2Base.sol b/contracts/plugins/assets/origin/OETHCollateralL2Base.sol index bfe939c40..efed598df 100644 --- a/contracts/plugins/assets/origin/OETHCollateralL2Base.sol +++ b/contracts/plugins/assets/origin/OETHCollateralL2Base.sol @@ -10,10 +10,17 @@ interface IWSuperOETHb { event Approval(address indexed owner, address indexed spender, uint256 value); event Deposit(address indexed caller, address indexed owner, uint256 assets, uint256 shares); event GovernorshipTransferred(address indexed previousGovernor, address indexed newGovernor); - event PendingGovernorshipTransfer(address indexed previousGovernor, address indexed newGovernor); + event PendingGovernorshipTransfer( + address indexed previousGovernor, + address indexed newGovernor + ); event Transfer(address indexed from, address indexed to, uint256 value); event Withdraw( - address indexed caller, address indexed receiver, address indexed owner, uint256 assets, uint256 shares + address indexed caller, + address indexed receiver, + address indexed owner, + uint256 assets, + uint256 shares ); function allowance(address owner, address spender) external view returns (uint256); @@ -64,7 +71,11 @@ interface IWSuperOETHb { function previewWithdraw(uint256 assets) external view returns (uint256); - function redeem(uint256 shares, address receiver, address owner) external returns (uint256); + function redeem( + uint256 shares, + address receiver, + address owner + ) external returns (uint256); function symbol() external view returns (string memory); @@ -74,13 +85,21 @@ interface IWSuperOETHb { function transfer(address recipient, uint256 amount) external returns (bool); - function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); function transferGovernance(address _newGovernor) external; function transferToken(address asset_, uint256 amount_) external; - function withdraw(uint256 assets, address receiver, address owner) external returns (uint256); + function withdraw( + uint256 assets, + address receiver, + address owner + ) external returns (uint256); } interface IMorphoChainlinkOracleV2 { @@ -130,7 +149,16 @@ contract OETHCollateralL2Base is ERC4626FiatCollateral { /// @return low {UoA/tok} The low price estimate /// @return high {UoA/tok} The high price estimate /// @return pegPrice {target/ref} The actual price observed in the peg - function tryPrice() external view override returns (uint192 low, uint192 high, uint192 pegPrice) { + function tryPrice() + external + view + override + returns ( + uint192 low, + uint192 high, + uint192 pegPrice + ) + { // {tar/tok} // {ETH/wsuperOETHb} uint192 targetPerTok = _safeWrap(targetPerTokChainlinkFeed.price() / FIX_ONE); From c396984c93a1ed1bc17624c8b0f919185ecfc5e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment?= Date: Wed, 6 Nov 2024 22:47:26 +0700 Subject: [PATCH 6/8] prettier --- test/plugins/individual-collateral/origin/constants.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/test/plugins/individual-collateral/origin/constants.ts b/test/plugins/individual-collateral/origin/constants.ts index 0225214a7..3e13d898f 100644 --- a/test/plugins/individual-collateral/origin/constants.ts +++ b/test/plugins/individual-collateral/origin/constants.ts @@ -19,7 +19,6 @@ export const BASE_FEEDS_TIMEOUT = { } export const BASE_ORACLE_ERROR = combinedError(fp('0.005'), fp('0.015')) - // Data export const PRICE_TIMEOUT = bn('604800') // 1 week export const ORACLE_TIMEOUT = bn(86400) // 24 hours in seconds From b4c2dfb9817dcb6b3f8ace53de11ca6964e401c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment?= Date: Thu, 7 Nov 2024 11:05:49 +0700 Subject: [PATCH 7/8] feat: simplify pegPrice. --- .../assets/origin/OETHCollateralL2Base.sol | 97 +------------------ 1 file changed, 1 insertion(+), 96 deletions(-) diff --git a/contracts/plugins/assets/origin/OETHCollateralL2Base.sol b/contracts/plugins/assets/origin/OETHCollateralL2Base.sol index efed598df..b371980db 100644 --- a/contracts/plugins/assets/origin/OETHCollateralL2Base.sol +++ b/contracts/plugins/assets/origin/OETHCollateralL2Base.sol @@ -6,101 +6,6 @@ import "../../../libraries/Fixed.sol"; import "../ERC4626FiatCollateral.sol"; import "../OracleLib.sol"; -interface IWSuperOETHb { - event Approval(address indexed owner, address indexed spender, uint256 value); - event Deposit(address indexed caller, address indexed owner, uint256 assets, uint256 shares); - event GovernorshipTransferred(address indexed previousGovernor, address indexed newGovernor); - event PendingGovernorshipTransfer( - address indexed previousGovernor, - address indexed newGovernor - ); - event Transfer(address indexed from, address indexed to, uint256 value); - event Withdraw( - address indexed caller, - address indexed receiver, - address indexed owner, - uint256 assets, - uint256 shares - ); - - function allowance(address owner, address spender) external view returns (uint256); - - function approve(address spender, uint256 amount) external returns (bool); - - function asset() external view returns (address); - - function balanceOf(address account) external view returns (uint256); - - function claimGovernance() external; - - function convertToAssets(uint256 shares) external view returns (uint256 assets); - - function convertToShares(uint256 assets) external view returns (uint256 shares); - - function decimals() external view returns (uint8); - - function decreaseAllowance(address spender, uint256 subtractedValue) external returns (bool); - - function deposit(uint256 assets, address receiver) external returns (uint256); - - function governor() external view returns (address); - - function increaseAllowance(address spender, uint256 addedValue) external returns (bool); - - function initialize() external; - - function isGovernor() external view returns (bool); - - function maxDeposit(address) external view returns (uint256); - - function maxMint(address) external view returns (uint256); - - function maxRedeem(address owner) external view returns (uint256); - - function maxWithdraw(address owner) external view returns (uint256); - - function mint(uint256 shares, address receiver) external returns (uint256); - - function name() external view returns (string memory); - - function previewDeposit(uint256 assets) external view returns (uint256); - - function previewMint(uint256 shares) external view returns (uint256); - - function previewRedeem(uint256 shares) external view returns (uint256); - - function previewWithdraw(uint256 assets) external view returns (uint256); - - function redeem( - uint256 shares, - address receiver, - address owner - ) external returns (uint256); - - function symbol() external view returns (string memory); - - function totalAssets() external view returns (uint256); - - function totalSupply() external view returns (uint256); - - function transfer(address recipient, uint256 amount) external returns (bool); - - function transferFrom( - address sender, - address recipient, - uint256 amount - ) external returns (bool); - - function transferGovernance(address _newGovernor) external; - - function transferToken(address asset_, uint256 amount_) external; - - function withdraw( - uint256 assets, - address receiver, - address owner - ) external returns (uint256); -} interface IMorphoChainlinkOracleV2 { function price() external view returns (uint256); @@ -178,6 +83,6 @@ contract OETHCollateralL2Base is ERC4626FiatCollateral { // {tar/ref} = {tar/tok} / {ref/tok} Get current market peg // ETH/superOETHb = ETH/wsuperOETHb / superOETHb/wsuperOETHb - pegPrice = targetPerTok.div(underlyingRefPerTok()); + pegPrice = FIX_ONE; } } From e705420b18bc6fb188d1f84d3f6a1b9ac85bbc7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment?= Date: Thu, 7 Nov 2024 11:07:22 +0700 Subject: [PATCH 8/8] prettier --- contracts/plugins/assets/origin/OETHCollateralL2Base.sol | 1 - 1 file changed, 1 deletion(-) diff --git a/contracts/plugins/assets/origin/OETHCollateralL2Base.sol b/contracts/plugins/assets/origin/OETHCollateralL2Base.sol index b371980db..402e0d5c5 100644 --- a/contracts/plugins/assets/origin/OETHCollateralL2Base.sol +++ b/contracts/plugins/assets/origin/OETHCollateralL2Base.sol @@ -6,7 +6,6 @@ import "../../../libraries/Fixed.sol"; import "../ERC4626FiatCollateral.sol"; import "../OracleLib.sol"; - interface IMorphoChainlinkOracleV2 { function price() external view returns (uint256); }