-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: packages * add interfaces & mocks * chore: update prettier package * chore: linting test files * fix: flashUnwrap unit test * build: pin truffle to v5.1.32 * update interface * add WSTETH price * change mock from STETH to WSTETH * update revert message * unit-test: WstethPricer.sol * fix typo * refactor: shorten require error strings to error codes & document - WstethPricer * feat: initial WstethPricer deployment script * docs: update README w/ WstethPricer deployment steps * docs: update docs & diagrams * fix: lint issues * refactor: rm redundant cast to address - WstethPricer * docs: update code comments - WstethPricer * docs: update Co-authored-by: CruzMolina <[email protected]>
- Loading branch information
1 parent
67a2bff
commit 6f4f969
Showing
85 changed files
with
51,446 additions
and
7,911 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity =0.6.10; | ||
|
||
interface WSTETHInterface { | ||
function name() external view returns (string memory); | ||
|
||
function symbol() external view returns (string memory); | ||
|
||
function decimals() external view returns (uint8); | ||
|
||
function stEthPerToken() external view returns (uint256); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 MockWSTETHToken is ERC20Upgradeable { | ||
uint256 public stEthPerToken; | ||
|
||
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 setStEthPerToken(uint256 _stEthPerToken) external { | ||
stEthPerToken = _stEthPerToken; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity =0.6.10; | ||
|
||
import {OracleInterface} from "../interfaces/OracleInterface.sol"; | ||
import {OpynPricerInterface} from "../interfaces/OpynPricerInterface.sol"; | ||
import {WSTETHInterface} from "../interfaces/WSTETHInterface.sol"; | ||
import {SafeMath} from "../packages/oz/SafeMath.sol"; | ||
|
||
/** | ||
* Error Codes | ||
* W1: cannot deploy pricer, wstETH address cannot be 0 | ||
* W2: cannot deploy pricer, underlying address cannot be 0 | ||
* W3: cannot deploy pricer, oracle address cannot be 0 | ||
* 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 | ||
*/ | ||
|
||
/** | ||
* @title WstethPricer | ||
* @author Opyn Team | ||
* @notice A Pricer contract for a wstETH token | ||
*/ | ||
contract WstethPricer is OpynPricerInterface { | ||
using SafeMath for uint256; | ||
|
||
/// @notice opyn oracle address | ||
OracleInterface public oracle; | ||
|
||
/// @notice wstETH token | ||
WSTETHInterface public wstETH; | ||
|
||
/// @notice underlying asset (WETH) | ||
address public underlying; | ||
|
||
/** | ||
* @param _wstETH wstETH | ||
* @param _underlying underlying asset for wstETH | ||
* @param _oracle Opyn Oracle contract address | ||
*/ | ||
constructor( | ||
address _wstETH, | ||
address _underlying, | ||
address _oracle | ||
) public { | ||
require(_wstETH != address(0), "W1"); | ||
require(_underlying != address(0), "W2"); | ||
require(_oracle != address(0), "W3"); | ||
|
||
wstETH = WSTETHInterface(_wstETH); | ||
oracle = OracleInterface(_oracle); | ||
underlying = _underlying; | ||
} | ||
|
||
/** | ||
* @notice get the live price for the asset | ||
* @dev overrides the getPrice function in OpynPricerInterface | ||
* @return price of 1 wstETH in USD, scaled by 1e8 | ||
*/ | ||
function getPrice() external view override returns (uint256) { | ||
uint256 underlyingPrice = oracle.getPrice(underlying); | ||
require(underlyingPrice > 0, "W4"); | ||
return _underlyingPriceToWstethPrice(underlyingPrice); | ||
} | ||
|
||
/** | ||
* @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 { | ||
(uint256 underlyingPriceExpiry, ) = oracle.getExpiryPrice(underlying, _expiryTimestamp); | ||
require(underlyingPriceExpiry > 0, "W5"); | ||
uint256 wstEthPrice = _underlyingPriceToWstethPrice(underlyingPriceExpiry); | ||
oracle.setExpiryPrice(address(wstETH), _expiryTimestamp, wstEthPrice); | ||
} | ||
|
||
/** | ||
* @dev convert underlying price to wstETH price with the wstETH to stETH exchange rate (1 stETH ≈ 1 ETH) | ||
* @param _underlyingPrice price of 1 underlying token (ie 1e18 WETH) in USD, scaled by 1e8 | ||
* @return price of 1 wstETH in USD, scaled by 1e8 | ||
*/ | ||
function _underlyingPriceToWstethPrice(uint256 _underlyingPrice) private view returns (uint256) { | ||
uint256 stEthPerWsteth = wstETH.stEthPerToken(); | ||
|
||
return stEthPerWsteth.mul(_underlyingPrice).div(1e18); | ||
} | ||
|
||
function getHistoricalPrice(uint80) external view override returns (uint256, uint256) { | ||
revert("W6"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
docs/contracts-documentation/interfaces/WSTETHInterface.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# `WSTETHInterface` | ||
|
||
## Functions: | ||
|
||
- `name() (external)` | ||
|
||
- `symbol() (external)` | ||
|
||
- `decimals() (external)` | ||
|
||
- `stEthPerToken() (external)` | ||
|
||
### Function `name() → string external` | ||
|
||
### Function `symbol() → string external` | ||
|
||
### Function `decimals() → uint8 external` | ||
|
||
### Function `stEthPerToken() → uint256 external` |
Oops, something went wrong.