-
Notifications
You must be signed in to change notification settings - Fork 97
Feat: StakedaoEcrvPricer #441
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
Open
CruzMolina
wants to merge
15
commits into
master
Choose a base branch
from
pricer/stakedao-ecrv-pricer
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
e5f6583
feat: initial ICurve contract
CruzMolina 6ee6c60
feat: initial IStakeDao contract
CruzMolina 4ad71d2
feat: initial StakedaoEcrvPricer contract
CruzMolina b5cd4ea
feat: initial StakedaoEcrvPricer deployment script
CruzMolina 7d3fd6a
docs: update README w/ StakedaoEcrvPricer deployment steps
CruzMolina d87d4ba
docs: update docs & diagrams
CruzMolina 80530cc
build: update package-lock.json
CruzMolina 3775dd3
refactor: store underlying as address - StakedaoEcrvPricer
CruzMolina 52418cb
refactor: streamline scaling underlying price, update code comments
CruzMolina 9003ef2
docs: update
CruzMolina 233016c
fix stakedao pricer
aparnakr 35bc1cd
fix the stakedao pricer naming mismatches
aparnakr 7439f63
updated docs
aparnakr 1d0ebb7
updated docs
aparnakr 54d8a73
update readme
aparnakr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,7 @@ | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| pragma solidity 0.6.10; | ||
|
|
||
| interface ICurve { | ||
| function get_virtual_price() external view returns (uint256); | ||
| } |
This file contains hidden or 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,10 @@ | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| import {ERC20Interface} from "./ERC20Interface.sol"; | ||
|
|
||
| pragma solidity 0.6.10; | ||
| pragma experimental ABIEncoderV2; | ||
|
|
||
| interface IStakeDao { | ||
| function getPricePerFullShare() external view returns (uint256); | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,104 @@ | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| pragma solidity 0.6.10; | ||
|
|
||
| import {ICurve} from "../interfaces/ICurve.sol"; | ||
| import {IStakeDao} from "../interfaces/IStakeDao.sol"; | ||
| import {OracleInterface} from "../interfaces/OracleInterface.sol"; | ||
| import {SafeMath} from "../packages/oz/SafeMath.sol"; | ||
|
|
||
| /** | ||
| * Error Codes | ||
| * P1: cannot deploy pricer, lpToken address cannot be 0 | ||
| * P2: cannot deploy pricer, underlying address cannot be 0 | ||
| * P3: cannot deploy pricer, oracle address cannot be 0 | ||
| * P4: cannot deploy pricer, curve address cannot be 0 | ||
| * P5: cannot retrieve price, underlying price is 0 | ||
| * P6: cannot set expiry price in oracle, underlying price is 0 and has not been set | ||
| * P7: cannot retrieve historical prices, getHistoricalPrice has been deprecated | ||
| */ | ||
|
|
||
| /** | ||
| * @title StakedaoPricer | ||
| * @author Opyn Team | ||
| * @notice A Pricer contract for a Stakedao lpToken | ||
| */ | ||
| contract StakedaoPricer { | ||
| using SafeMath for uint256; | ||
|
|
||
| /// @notice curve pool | ||
| ICurve public curve; | ||
|
|
||
| /// @notice lpToken that this pricer will a get price for | ||
| IStakeDao public lpToken; | ||
|
|
||
| /// @notice opyn oracle address | ||
| OracleInterface public oracle; | ||
|
|
||
| /// @notice underlying asset for this lpToken | ||
| address public underlying; | ||
|
|
||
| /** | ||
| * @param _lpToken lpToken asset | ||
| * @param _underlying underlying asset for this lpToken | ||
| * @param _oracle Opyn Oracle contract address | ||
| * @param _curve curve pool contract address | ||
| */ | ||
| constructor( | ||
| address _lpToken, | ||
| address _underlying, | ||
| address _oracle, | ||
| address _curve | ||
| ) public { | ||
| require(_lpToken != address(0), "P1"); | ||
| require(_underlying != address(0), "P2"); | ||
| require(_oracle != address(0), "P3"); | ||
| require(_curve != address(0), "P4"); | ||
|
|
||
| lpToken = IStakeDao(_lpToken); | ||
| underlying = _underlying; | ||
| oracle = OracleInterface(_oracle); | ||
| curve = ICurve(_curve); | ||
| } | ||
|
|
||
| /** | ||
| * @notice get the live price for the asset | ||
| * @dev overrides the getPrice function in OpynPricerInterface | ||
| * @return price of 1 lpToken in USD, scaled by 1e8 | ||
| */ | ||
| function getPrice() external view returns (uint256) { | ||
| uint256 underlyingPrice = oracle.getPrice(address(underlying)); | ||
| require(underlyingPrice > 0, "P5"); | ||
| return _underlyingPriceToYtokenPrice(underlyingPrice); | ||
| } | ||
|
|
||
| /** | ||
| * @notice set the expiry price in the oracle | ||
| * @dev requires that the underlying price has been set before setting a lpToken price | ||
| * @param _expiryTimestamp expiry to set a price for | ||
| */ | ||
| function setExpiryPriceInOracle(uint256 _expiryTimestamp) external { | ||
| (uint256 underlyingPriceExpiry, ) = oracle.getExpiryPrice(underlying, _expiryTimestamp); | ||
| require(underlyingPriceExpiry > 0, "P6"); | ||
| uint256 lpTokenPrice = _underlyingPriceToYtokenPrice(underlyingPriceExpiry); | ||
| oracle.setExpiryPrice(address(lpToken), _expiryTimestamp, lpTokenPrice); | ||
| } | ||
|
|
||
| /** | ||
| * @dev convert underlying price to lpToken price with the lpToken to underlying exchange rate | ||
| * @param _underlyingPrice price of 1 underlying token (hardcoded 1e18 for WETH) in USD, scaled by 1e8 | ||
| * @return price of 1 lpToken in USD, scaled by 1e8 | ||
| */ | ||
| function _underlyingPriceToYtokenPrice(uint256 _underlyingPrice) private view returns (uint256) { | ||
| uint256 pricePerShare = lpToken.getPricePerFullShare(); // 18 decimals | ||
| uint256 curvePrice = curve.get_virtual_price(); // 18 decimals | ||
|
|
||
| // scale by 1e36 to return price of 1 lpToken in USD, scaled by 1e8 | ||
| // assumes underlyingPrice is 1e8, curve price is 1e18, pricePerShare is 1e18 | ||
| return pricePerShare.mul(_underlyingPrice).mul(curvePrice).div(1e36); | ||
| } | ||
|
|
||
| function getHistoricalPrice(uint80) external pure returns (uint256, uint256) { | ||
| revert("P7"); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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,15 @@ | ||
| # `ICurve` | ||
|
|
||
| ## Functions: | ||
|
|
||
| - `add_liquidity(uint256[2] amounts, uint256 minAmount) (external)` | ||
|
|
||
| - `remove_liquidity_one_coin(uint256 _token_amount, int128 i, uint256 _minAmount) (external)` | ||
|
|
||
| - `get_virtual_price() (external)` | ||
|
|
||
| ### Function `add_liquidity(uint256[2] amounts, uint256 minAmount) → uint256 external` | ||
|
|
||
| ### Function `remove_liquidity_one_coin(uint256 _token_amount, int128 i, uint256 _minAmount) → uint256 external` | ||
|
|
||
| ### Function `get_virtual_price() → uint256 external` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.