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

Feat: StakedaoEcrvPricer #441

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
refactor: streamline scaling underlying price, update code comments
CruzMolina committed Aug 19, 2021
commit 52418cbf9cdec44ea47eeddf2e935d1a9d1da532
11 changes: 6 additions & 5 deletions contracts/pricers/StakedaoEcrvPricer.sol
Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@ contract StakedaoEcrvPricer {
/**
* @notice get the live price for the asset
* @dev overrides the getPrice function in OpynPricerInterface
* @return price of 1e8 lpToken in USD, scaled by 1e8
* @return price of 1 lpToken in USD, scaled by 1e8
*/
function getPrice() external view returns (uint256) {
uint256 underlyingPrice = oracle.getPrice(address(underlying));
@@ -86,15 +86,16 @@ contract StakedaoEcrvPricer {

/**
* @dev convert underlying price to lpToken price with the lpToken to underlying exchange rate
* @param _underlyingPrice price of 1 underlying token (ie 1e6 USDC, 1e18 WETH) in USD, scaled by 1e8
* @return price of 1e8 lpToken in USD, scaled by 1e8
* @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();
uint8 underlyingDecimals = 18;
uint256 curvePrice = curve.get_virtual_price();

return pricePerShare.mul(_underlyingPrice).mul(curvePrice).div(10**uint256(2 * underlyingDecimals));
// scale by 1e36 to return price of 1 lpToken in USD, scaled by 1e8
// assumes underlying (WETH) is 1e18, curve price is 1e18
return pricePerShare.mul(_underlyingPrice).mul(curvePrice).div(1e36);
}

function getHistoricalPrice(uint80) external pure returns (uint256, uint256) {