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

OETH L2 Base plugin #1225

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions common/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export interface ITokens {
wsgUSDbC?: string
yvCurveUSDPcrvUSD?: string
yvCurveUSDCcrvUSD?: string
wsuperOETHb?: string

pyUSD?: string
aEthPyUSD?: string
Expand Down Expand Up @@ -536,6 +537,7 @@ export const networkConfig: { [key: string]: INetworkConfig } = {
USDz: '0x04D5ddf5f3a8939889F11E97f8c4BB48317F1938',
meUSD: '0xbb819D845b573B5D7C538F5b85057160cfb5f313',
AERO: '0x940181a94A35A4569E4529A3CDfB74e38FD98631',
wsuperOETHb: '0x7FcD174E80f264448ebeE8c88a7C4476AAF58Ea6'
},
chainlinkFeeds: {
DAI: '0x591e79239a7d679378ec8c847e5038150364c78f', // 0.3%, 24hr
Expand All @@ -555,6 +557,7 @@ export const networkConfig: { [key: string]: INetworkConfig } = {
eUSD: '0x9b2C948dbA5952A1f5Ab6fA16101c1392b8da1ab', // 0.5%, 24h
USDz: '0xe25969e2Fa633a0C027fAB8F30Fc9C6A90D60B48', // 0.5%, 24h
AERO: '0x4EC5970fC728C5f65ba413992CD5fF6FD70fcfF0', // 0.5%, 24h
wsuperOETHb: '0x28C964c985fe84736fAdc7Cf0bBd58B54bc7CF93'
},
GNOSIS_EASY_AUCTION: '0xb1875Feaeea32Bbb02DE83D81772e07E37A40f02', // mock
COMET_REWARDS: '0x123964802e6ABabBE1Bc9547D72Ef1B69B00A6b1',
Expand Down
190 changes: 190 additions & 0 deletions contracts/plugins/assets/origin/OETHCollateralL2Base.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;

import "@openzeppelin/contracts/utils/math/Math.sol";
import "../../../libraries/Fixed.sol";
import "../AppreciatingFiatCollateral.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);
}

/**
* @title Origin Staked ETH Collateral for Base L2
* @notice Collateral plugin for Origin OETH,
* tok = wsuperOETHb (wrapped superOETHb)
* ref = superOETHb (pegged to ETH 1:1)
* tar = ETH
* UoA = USD
*/
contract OETHCollateralL2Base is AppreciatingFiatCollateral {
using OracleLib for AggregatorV3Interface;
using FixLib for uint192;

IMorphoChainlinkOracleV2 public immutable targetPerTokChainlinkFeed; // {tar/token}

AggregatorV3Interface public immutable uoaPerTargetChainlinkFeed; // {UoA/tar}
uint48 public immutable uoaPerTargetChainlinkTimeout; // {s}

/// @param config.chainlinkFeed - ignored
/// @param config.oracleTimeout - ignored
/// @param config.oracleError {1} Should be the oracle error for UoA/tok
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be the combined oracle error I think, since it is applied post-product

constructor(
CollateralConfig memory config,
uint192 revenueHiding,
IMorphoChainlinkOracleV2 _targetPerTokChainlinkFeed,
AggregatorV3Interface _uoaPerTargetChainlinkFeed,
uint48 _uoaPerTargetChainlinkTimeout
) AppreciatingFiatCollateral(config, revenueHiding) {
require(config.defaultThreshold != 0, "defaultThreshold zero");

require(address(_targetPerTokChainlinkFeed) != address(0), "targetPerTokFeed missing");
require(address(_uoaPerTargetChainlinkFeed) != address(0), "uoaPerTargetFeed missing");

targetPerTokChainlinkFeed = _targetPerTokChainlinkFeed;

uoaPerTargetChainlinkFeed = _uoaPerTargetChainlinkFeed;
uoaPerTargetChainlinkTimeout = _uoaPerTargetChainlinkTimeout;

maxOracleTimeout = uint48(Math.max(maxOracleTimeout, _uoaPerTargetChainlinkTimeout));
}

/// Can revert, used by other contract functions in order to catch errors
/// @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
)
{
// {tar/tok}
// {ETH/wsuperOETHb}
uint192 targetPerTok = _safeWrap(targetPerTokChainlinkFeed.price()) / 1e18;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is an overflow risk, should probably move the paren outside the 1e18


// {UoA/tar}
// {USD/ETH}
uint192 uoaPerTar = uoaPerTargetChainlinkFeed.price(uoaPerTargetChainlinkTimeout);

// {UoA/tok} = {UoA/tar} * {tar/tok}
// USD/wsuperOETHb = USD/ETH * ETH/wsuperOETHb
uint192 p = uoaPerTar.mul(targetPerTok);
uint192 err = p.mul(oracleError, CEIL);

high = p + err;
low = p - err;
// assert(low <= high); obviously true just by inspection

// {tar/ref} = {tar/tok} / {ref/tok} Get current market peg
// 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) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could delete this function entirely if you change the inheritance to ERC4626FiatCollateral

return _safeWrap(IWSuperOETHb(address(erc20)).convertToAssets(FIX_ONE));
}
}
Loading
Loading