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

draft steth pricer #439

Closed
wants to merge 14 commits into from
4 changes: 3 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ workflows:
- build
- integration-test:
requires:
- build
- unit-test
# - e2e-test:
# context: COVERALLS_REPO_TOKEN
# requires:
Expand All @@ -38,6 +38,8 @@ workflows:
context: COVERALLS_REPO_TOKEN
requires:
- unit-test
- integration-test
- coverage

jobs:

Expand Down
8 changes: 4 additions & 4 deletions contracts/core/Controller.sol
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ contract Controller is Initializable, OwnableUpgradeSafe, ReentrancyGuardUpgrade
/**
* @notice modifier to check if the system is not partially paused, where only redeem and settleVault is allowed
*/
modifier notPartiallyPaused {
modifier notPartiallyPaused() {
_isNotPartiallyPaused();

_;
Expand All @@ -224,7 +224,7 @@ contract Controller is Initializable, OwnableUpgradeSafe, ReentrancyGuardUpgrade
/**
* @notice modifier to check if the system is not fully paused, where no functionality is allowed
*/
modifier notFullyPaused {
modifier notFullyPaused() {
_isNotFullyPaused();

_;
Expand All @@ -233,7 +233,7 @@ contract Controller is Initializable, OwnableUpgradeSafe, ReentrancyGuardUpgrade
/**
* @notice modifier to check if sender is the fullPauser address
*/
modifier onlyFullPauser {
modifier onlyFullPauser() {
require(msg.sender == fullPauser, "C1");

_;
Expand All @@ -242,7 +242,7 @@ contract Controller is Initializable, OwnableUpgradeSafe, ReentrancyGuardUpgrade
/**
* @notice modifier to check if the sender is the partialPauser address
*/
modifier onlyPartialPauser {
modifier onlyPartialPauser() {
require(msg.sender == partialPauser, "C2");

_;
Expand Down
12 changes: 12 additions & 0 deletions contracts/interfaces/STETHInterface.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.6.10;

interface STETHInterface {
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to use the wstETH interface here, which doesn't include getPooledEthByShares.

function name() external view returns (string memory);

function symbol() external view returns (string memory);

function decimals() external view returns (uint8);

function getPooledEthByShares(uint256 sharesAmount) external view returns (uint256);
}
2 changes: 1 addition & 1 deletion contracts/mocks/MockDumbERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ contract MockDumbERC20 {
return true;
}

function allowance(address owner, address spender) public virtual view returns (uint256) {
function allowance(address owner, address spender) public view virtual returns (uint256) {
return _allowances[owner][spender];
}

Expand Down
21 changes: 21 additions & 0 deletions contracts/mocks/MockSTETHToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.6.10;

import {ERC20Upgradeable} from "../packages/oz/upgradeability/ERC20Upgradeable.sol";

contract MockSTETHToken is ERC20Upgradeable {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a mock for stETH, but we need a wstETH token, which has doesn't have getPooledEthByShares.

mapping(uint256 => uint256) public getPooledEthByShares;

constructor(string memory _name, string memory _symbol) public {
__ERC20_init_unchained(_name, _symbol);
_setupDecimals(18);
}

function mint(address account, uint256 amount) public {
_mint(account, amount);
}

function setPooledEthByShares(uint256 _pooledEthByShares) external {
getPooledEthByShares[1 ether] = _pooledEthByShares;
}
}
4 changes: 2 additions & 2 deletions contracts/packages/oz/Context.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ pragma solidity 0.6.10;
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal virtual view returns (address payable) {
function _msgSender() internal view virtual returns (address payable) {
return msg.sender;
}

function _msgData() internal virtual view returns (bytes memory) {
function _msgData() internal view virtual returns (bytes memory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
Expand Down
6 changes: 3 additions & 3 deletions contracts/packages/oz/upgradeability/ERC20Upgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeabl
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public override view returns (uint256) {
function totalSupply() public view override returns (uint256) {
return _totalSupply;
}

/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public override view returns (uint256) {
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}

Expand All @@ -127,7 +127,7 @@ contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeabl
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public virtual override view returns (uint256) {
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ abstract contract ContextUpgradeable is Initializable {

function __Context_init_unchained() internal initializer {}

function _msgSender() internal virtual view returns (address payable) {
function _msgSender() internal view virtual returns (address payable) {
return msg.sender;
}

function _msgData() internal virtual view returns (bytes memory) {
function _msgData() internal view virtual returns (bytes memory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
Expand Down
14 changes: 7 additions & 7 deletions contracts/packages/oz/upgradeability/Proxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ abstract contract Proxy {
* @dev Tells the address of the implementation where every call will be delegated.
* @return address of the implementation to which it will be delegated
*/
function implementation() public virtual view returns (address);
function implementation() public view virtual returns (address);

/**
* @dev Fallback function allowing to perform a delegatecall to the given implementation.
Expand All @@ -30,12 +30,12 @@ abstract contract Proxy {
returndatacopy(ptr, 0, size)

switch result
case 0 {
revert(ptr, size)
}
default {
return(ptr, size)
}
case 0 {
revert(ptr, size)
}
default {
return(ptr, size)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ contract UpgradeabilityProxy is Proxy {
* @dev Tells the address of the current implementation
* @return impl address of the current implementation
*/
function implementation() public override view returns (address impl) {
function implementation() public view override returns (address impl) {
bytes32 position = implementationPosition;
assembly {
impl := sload(position)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ abstract contract EIP712Upgradeable is Initializable {
/* solhint-disable var-name-mixedcase */
bytes32 private _HASHED_NAME;
bytes32 private _HASHED_VERSION;
bytes32 private constant _TYPE_HASH = keccak256(
"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
);
bytes32 private constant _TYPE_HASH =
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");

/* solhint-enable var-name-mixedcase */

Expand Down Expand Up @@ -102,7 +101,7 @@ abstract contract EIP712Upgradeable is Initializable {
* NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs
* are a concern.
*/
function _EIP712NameHash() internal virtual view returns (bytes32) {
function _EIP712NameHash() internal view virtual returns (bytes32) {
return _HASHED_NAME;
}

Expand All @@ -112,7 +111,7 @@ abstract contract EIP712Upgradeable is Initializable {
* NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs
* are a concern.
*/
function _EIP712VersionHash() internal virtual view returns (bytes32) {
function _EIP712VersionHash() internal view virtual returns (bytes32) {
return _HASHED_VERSION;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ abstract contract ERC20PermitUpgradeable is
/**
* @dev See {IERC20Permit-nonces}.
*/
function nonces(address owner) public override view returns (uint256) {
function nonces(address owner) public view override returns (uint256) {
return _nonces[owner].current();
}

/**
* @dev See {IERC20Permit-DOMAIN_SEPARATOR}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external override view returns (bytes32) {
function DOMAIN_SEPARATOR() external view override returns (bytes32) {
return _domainSeparatorV4();
}

Expand Down
4 changes: 2 additions & 2 deletions contracts/pricers/ChainlinkPricer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ contract ChainLinkPricer is OpynPricerInterface {
* @dev overides the getPrice function in OpynPricerInterface
* @return price of the asset in USD, scaled by 1e8
*/
function getPrice() external override view returns (uint256) {
function getPrice() external view override returns (uint256) {
(, int256 answer, , , ) = aggregator.latestRoundData();
require(answer > 0, "ChainLinkPricer: price is lower than 0");
// chainlink's answer is already 1e8
Expand All @@ -92,7 +92,7 @@ contract ChainLinkPricer is OpynPricerInterface {
* @param _roundId chainlink round id
* @return round price and timestamp
*/
function getHistoricalPrice(uint80 _roundId) external override view returns (uint256, uint256) {
function getHistoricalPrice(uint80 _roundId) external view override returns (uint256, uint256) {
(, int256 price, , uint256 roundTimestamp, ) = aggregator.getRoundData(_roundId);
return (_scaleToBase(uint256(price)), roundTimestamp);
}
Expand Down
82 changes: 82 additions & 0 deletions contracts/pricers/STETHPricer.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.6.10;

import {OracleInterface} from "../interfaces/OracleInterface.sol";
import {OpynPricerInterface} from "../interfaces/OpynPricerInterface.sol";
import {STETHInterface} from "../interfaces/STETHInterface.sol";
import {ERC20Interface} from "../interfaces/ERC20Interface.sol";
import {SafeMath} from "../packages/oz/SafeMath.sol";

/**
* @notice A Pricer contract for a Yearn yToken
*/
contract STETHPricer is OpynPricerInterface {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should probably call it WSTETHPricer as it is pricing wstETH collateral.

using SafeMath for uint256;

/// @notice opyn oracle address
OracleInterface public oracle;

/// @notice stETH token
STETHInterface public stETH;

/// @notice underlying asset for this yToken
ERC20Interface public underlying;

/**
* @param _stETH stETH
* @param _underlying underlying asset for stETH
* @param _oracle Opyn Oracle contract address
*/
constructor(
address _stETH,
Copy link
Contributor

Choose a reason for hiding this comment

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

Throughout, I think should change to wstETH to make it clear we are collateralizing with wstETH.

address _underlying,
address _oracle
) public {
require(_stETH != address(0), "STETHPricer: stETH address can not be 0");
require(_underlying != address(0), "STETHPricer: underlying address can not be 0");
require(_oracle != address(0), "STETHPricer: oracle address can not be 0");

stETH = STETHInterface(_stETH);
underlying = ERC20Interface(_underlying);
oracle = OracleInterface(_oracle);
}

/**
* @notice get the live price for the asset
* @dev overrides the getPrice function in OpynPricerInterface
* @return price of 1e18 stETH in USD, scaled by 1e18
*/
function getPrice() external view override returns (uint256) {
uint256 underlyingPrice = oracle.getPrice(address(underlying));
require(underlyingPrice > 0, "STETHPricer: underlying price is 0");
return _underlyingPriceToSTETHPrice(underlyingPrice);
}

/**
* @notice set the expiry price in the oracle
* @dev requires that the underlying price has been set before setting a stETH price
* @param _expiryTimestamp expiry to set a price for
*/
function setExpiryPriceInOracle(uint256 _expiryTimestamp) external {
(uint256 underlyingPriceExpiry, ) = oracle.getExpiryPrice(address(underlying), _expiryTimestamp);
require(underlyingPriceExpiry > 0, "STETHPricer: underlying price not set yet");
uint256 stETHPrice = _underlyingPriceToSTETHPrice(underlyingPriceExpiry);
oracle.setExpiryPrice(address(stETH), _expiryTimestamp, stETHPrice);
}

/**
* @dev convert underlying price to stETH price with the stETH to underlying exchange rate
* @param _underlyingPrice price of 1 underlying token (ie 1e18 WETH) in USD, scaled by 1e8
* @return price of 1e8 stETH in USD, scaled by 1e8
*/
function _underlyingPriceToSTETHPrice(uint256 _underlyingPrice) private view returns (uint256) {
uint256 pricePerShare = stETH.getPooledEthByShares(1 ether);
Copy link
Contributor

Choose a reason for hiding this comment

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

Here we can use stEthPerToken() from the wstETH contract

https://docs.lido.fi/contracts/wsteth

uint8 underlyingDecimals = underlying.decimals();

return pricePerShare.mul(_underlyingPrice).div(10**uint256(underlyingDecimals));
}

function getHistoricalPrice(uint80 _roundId) external view override returns (uint256, uint256) {
revert("STETHPricer: Deprecated");
}
}
4 changes: 2 additions & 2 deletions contracts/pricers/YearnPricer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ contract YearnPricer is OpynPricerInterface {
* @dev overrides the getPrice function in OpynPricerInterface
* @return price of 1e8 yToken in USD, scaled by 1e8
*/
function getPrice() external override view returns (uint256) {
function getPrice() external view override returns (uint256) {
uint256 underlyingPrice = oracle.getPrice(address(underlying));
require(underlyingPrice > 0, "YearnPricer: underlying price is 0");
return _underlyingPriceToYtokenPrice(underlyingPrice);
Expand Down Expand Up @@ -76,7 +76,7 @@ contract YearnPricer is OpynPricerInterface {
return pricePerShare.mul(_underlyingPrice).div(10**uint256(underlyingDecimals));
}

function getHistoricalPrice(uint80 _roundId) external override view returns (uint256, uint256) {
function getHistoricalPrice(uint80 _roundId) external view override returns (uint256, uint256) {
revert("YearnPricer: Deprecated");
}
}
Loading