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

Make setExpiryPrice for YearnPricer and WstethPricer permissioned #447

Closed
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
20 changes: 18 additions & 2 deletions contracts/pricers/WstethPricer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {SafeMath} from "../packages/oz/SafeMath.sol";
* W4: cannot retrieve price, underlying price is 0
* W5: cannot set expiry price in oracle, underlying price is 0 and has not been set
* W6: cannot retrieve historical prices, getHistoricalPrice has been deprecated
* W7: cannot deploy pricer, bot is 0
*/

/**
Expand All @@ -33,6 +34,9 @@ contract WstethPricer is OpynPricerInterface {
/// @notice underlying asset (WETH)
address public underlying;

/// @notice bot address that is allowed to call setExpiryPriceInOracle
address public bot;

/**
* @param _wstETH wstETH
* @param _underlying underlying asset for wstETH
Expand All @@ -41,15 +45,18 @@ contract WstethPricer is OpynPricerInterface {
constructor(
address _wstETH,
address _underlying,
address _oracle
address _oracle,
address _bot
) public {
require(_wstETH != address(0), "W1");
require(_underlying != address(0), "W2");
require(_oracle != address(0), "W3");
require(_bot != address(0), "W7");

wstETH = WSTETHInterface(_wstETH);
oracle = OracleInterface(_oracle);
underlying = _underlying;
bot = _bot;
}

/**
Expand All @@ -63,12 +70,21 @@ contract WstethPricer is OpynPricerInterface {
return _underlyingPriceToWstethPrice(underlyingPrice);
}

/**
* @notice modifier to check if sender address is equal to bot address
*/
modifier onlyBot() {
require(msg.sender == bot, "WstethPricer: unauthorized sender");

_;
}

/**
* @notice set the expiry price in the oracle
* @dev requires that the underlying price has been set before setting a wstETH price
* @param _expiryTimestamp expiry to set a price for
*/
function setExpiryPriceInOracle(uint256 _expiryTimestamp) external {
function setExpiryPriceInOracle(uint256 _expiryTimestamp) external onlyBot {
(uint256 underlyingPriceExpiry, ) = oracle.getExpiryPrice(underlying, _expiryTimestamp);
require(underlyingPriceExpiry > 0, "W5");
uint256 wstEthPrice = _underlyingPriceToWstethPrice(underlyingPriceExpiry);
Expand Down
20 changes: 17 additions & 3 deletions contracts/pricers/YearnPricer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ contract YearnPricer is OpynPricerInterface {
/// @notice underlying asset for this yToken
ERC20Interface public underlying;

/// @notice bot address that is allowed to call setExpiryPriceInOracle
address public bot;

/**
* @param _yToken yToken asset
* @param _underlying underlying asset for this yToken
Expand All @@ -30,7 +33,8 @@ contract YearnPricer is OpynPricerInterface {
constructor(
address _yToken,
address _underlying,
address _oracle
address _oracle,
address _bot
) public {
require(_yToken != address(0), "YearnPricer: yToken address can not be 0");
require(_underlying != address(0), "YearnPricer: underlying address can not be 0");
Expand All @@ -39,6 +43,7 @@ contract YearnPricer is OpynPricerInterface {
yToken = YearnVaultInterface(_yToken);
underlying = ERC20Interface(_underlying);
oracle = OracleInterface(_oracle);
bot = _bot;
}

/**
Expand All @@ -52,12 +57,21 @@ contract YearnPricer is OpynPricerInterface {
return _underlyingPriceToYtokenPrice(underlyingPrice);
}

/**
* @notice modifier to check if sender address is equal to bot address
*/
modifier onlyBot() {
require(msg.sender == bot, "YearnPricer: unauthorized sender");

_;
}

/**
* @notice set the expiry price in the oracle
* @dev requires that the underlying price has been set before setting a yToken price
* @param _expiryTimestamp expiry to set a price for
*/
function setExpiryPriceInOracle(uint256 _expiryTimestamp) external {
function setExpiryPriceInOracle(uint256 _expiryTimestamp) external onlyBot {
(uint256 underlyingPriceExpiry, ) = oracle.getExpiryPrice(address(underlying), _expiryTimestamp);
require(underlyingPriceExpiry > 0, "YearnPricer: underlying price not set yet");
uint256 yTokenPrice = _underlyingPriceToYtokenPrice(underlyingPriceExpiry);
Expand All @@ -76,7 +90,7 @@ contract YearnPricer is OpynPricerInterface {
return pricePerShare.mul(_underlyingPrice).div(10**uint256(underlyingDecimals));
}

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