Skip to content

Commit

Permalink
Merge pull request #14 from Gearbox-protocol/crvusd-price-feed
Browse files Browse the repository at this point in the history
feat: crvUSD price feed
  • Loading branch information
0xmikko authored Aug 7, 2023
2 parents b91d5a4 + 79208d4 commit 394d65d
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 20 deletions.
11 changes: 7 additions & 4 deletions contracts/oracles/SingleAssetLPPriceFeed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ abstract contract SingleAssetLPPriceFeed is LPPriceFeed {
uint32 public immutable stalenessPeriod;
bool public immutable skipCheck;

constructor(address addressProvider, address _lpToken, address _priceFeed, uint32 _stalenessPeriod)
LPPriceFeed(addressProvider, _lpToken, _lpToken)
nonZeroAddress(_priceFeed)
{
constructor(
address addressProvider,
address _lpToken,
address _lpContract,
address _priceFeed,
uint32 _stalenessPeriod
) LPPriceFeed(addressProvider, _lpToken, _lpContract) nonZeroAddress(_priceFeed) {
priceFeed = _priceFeed;
stalenessPeriod = _stalenessPeriod;
skipCheck = _validatePriceFeed(_priceFeed, _stalenessPeriod);
Expand Down
2 changes: 1 addition & 1 deletion contracts/oracles/aave/WrappedAaveV2PriceFeed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ contract WrappedAaveV2PriceFeed is SingleAssetLPPriceFeed {
PriceFeedType public constant override priceFeedType = PriceFeedType.WRAPPED_AAVE_V2_ORACLE;

constructor(address addressProvider, address _waToken, address _priceFeed, uint32 _stalenessPeriod)
SingleAssetLPPriceFeed(addressProvider, _waToken, _priceFeed, _stalenessPeriod)
SingleAssetLPPriceFeed(addressProvider, _waToken, _waToken, _priceFeed, _stalenessPeriod)
{
_initLimiter();
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/oracles/compound/CompoundV2PriceFeed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ contract CompoundV2PriceFeed is SingleAssetLPPriceFeed {
PriceFeedType public constant override priceFeedType = PriceFeedType.COMPOUND_V2_ORACLE;

constructor(address addressProvider, address _cToken, address _priceFeed, uint32 _stalenessPeriod)
SingleAssetLPPriceFeed(addressProvider, _cToken, _priceFeed, _stalenessPeriod)
SingleAssetLPPriceFeed(addressProvider, _cToken, _cToken, _priceFeed, _stalenessPeriod)
{
_initLimiter();
}
Expand Down
35 changes: 35 additions & 0 deletions contracts/oracles/curve/CurveUSDPriceFeed.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// SPDX-License-Identifier: BUSL-1.1
// Gearbox Protocol. Generalized leverage for DeFi protocols
// (c) Gearbox Foundation, 2023.
pragma solidity ^0.8.17;

import {SingleAssetLPPriceFeed} from "../SingleAssetLPPriceFeed.sol";
import {PriceFeedType} from "@gearbox-protocol/sdk/contracts/PriceFeedType.sol";
import {WAD} from "@gearbox-protocol/core-v2/contracts/libraries/Constants.sol";

interface IPool {
function price_oracle() external view returns (uint256);
}

/// @title crvUSD price feed
/// @notice Computes crvUSD price as product of crvUSD-USDC stableswap pool exchange rate and USDC price feed.
/// While crvUSD is not an LP token itself, the pricing logic is fairly similar, so existing infrastructure
/// is reused. Particularly, the same bounding mechanism is applied to the pool exchange rate.
contract CurveUSDPriceFeed is SingleAssetLPPriceFeed {
uint256 public constant override version = 3_00;
PriceFeedType public constant override priceFeedType = PriceFeedType.CURVE_USD_ORACLE;

constructor(address addressProvider, address _crvUSD, address _pool, address _priceFeed, uint32 _stalenessPeriod)
SingleAssetLPPriceFeed(addressProvider, _crvUSD, _pool, _priceFeed, _stalenessPeriod)
{
_initLimiter();
}

function getLPExchangeRate() public view override returns (uint256) {
return IPool(lpContract).price_oracle();
}

function getScale() public pure override returns (uint256) {
return WAD;
}
}
2 changes: 1 addition & 1 deletion contracts/oracles/erc4626/ERC4626PriceFeed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ contract ERC4626PriceFeed is SingleAssetLPPriceFeed {
uint256 immutable _assetUnit;

constructor(address addressProvider, address _vault, address _assetPriceFeed, uint32 _stalenessPeriod)
SingleAssetLPPriceFeed(addressProvider, _vault, _assetPriceFeed, _stalenessPeriod)
SingleAssetLPPriceFeed(addressProvider, _vault, _vault, _assetPriceFeed, _stalenessPeriod)
{
_shareUnit = 10 ** IERC4626(_vault).decimals();
_assetUnit = 10 ** ERC20(IERC4626(_vault).asset()).decimals();
Expand Down
2 changes: 1 addition & 1 deletion contracts/oracles/lido/WstETHPriceFeed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ contract WstETHPriceFeed is SingleAssetLPPriceFeed {
PriceFeedType public constant override priceFeedType = PriceFeedType.WSTETH_ORACLE;

constructor(address addressProvider, address _wstETH, address _priceFeed, uint32 _stalenessPeriod)
SingleAssetLPPriceFeed(addressProvider, _wstETH, _priceFeed, _stalenessPeriod)
SingleAssetLPPriceFeed(addressProvider, _wstETH, _wstETH, _priceFeed, _stalenessPeriod)
{
_initLimiter();
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/oracles/yearn/YearnPriceFeed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ contract YearnPriceFeed is SingleAssetLPPriceFeed {
uint256 immutable _scale;

constructor(address addressProvider, address _yVault, address _priceFeed, uint32 _stalenessPeriod)
SingleAssetLPPriceFeed(addressProvider, _yVault, _priceFeed, _stalenessPeriod)
SingleAssetLPPriceFeed(addressProvider, _yVault, _yVault, _priceFeed, _stalenessPeriod)
{
_scale = 10 ** IYVault(_yVault).decimals();
_initLimiter();
Expand Down
46 changes: 40 additions & 6 deletions contracts/test/suites/PriceFeedDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
SingeTokenPriceFeedData,
CompositePriceFeedData,
CurvePriceFeedData,
CrvUsdPriceFeedData,
GenericLPPriceFeedData,
TheSamePriceFeedData,
RedStonePriceFeedData
Expand All @@ -33,6 +34,7 @@ import {WstETHPriceFeed} from "../../oracles/lido/WstETHPriceFeed.sol";
import {CompositePriceFeed} from "../../oracles/CompositePriceFeed.sol";
import {BoundedPriceFeed} from "../../oracles/BoundedPriceFeed.sol";

import {CurveUSDPriceFeed} from "../../oracles/curve/CurveUSDPriceFeed.sol";
import {CurveStableLPPriceFeed} from "../../oracles/curve/CurveStableLPPriceFeed.sol";
import {CurveCryptoLPPriceFeed} from "../../oracles/curve/CurveCryptoLPPriceFeed.sol";

Expand Down Expand Up @@ -83,8 +85,9 @@ contract PriceFeedDeployer is Test, PriceFeedDataLive {
}
}
}

// BOUNDED PRICE FEEDS
{
// BOUNDED_PRICE_FEEDS
BoundedPriceFeedData[] memory boundedPriceFeeds = boundedPriceFeedsByNetwork[chainId];
len = boundedPriceFeeds.length;
unchecked {
Expand All @@ -110,8 +113,9 @@ contract PriceFeedDeployer is Test, PriceFeedDataLive {
}
}
}

// COMPOSITE PRICE FEEDS
{
// COMPOSITE_PRICE_FEEDS
CompositePriceFeedData[] memory compositePriceFeeds = compositePriceFeedsByNetwork[chainId];
len = compositePriceFeeds.length;
unchecked {
Expand Down Expand Up @@ -147,6 +151,7 @@ contract PriceFeedDeployer is Test, PriceFeedDataLive {
}
}
}

// ZERO PRICE FEEDS
{
SingeTokenPriceFeedData[] memory zeroPriceFeeds = zeroPriceFeedsByNetwork[chainId];
Expand All @@ -158,15 +163,43 @@ contract PriceFeedDeployer is Test, PriceFeedDataLive {
address token = tokenTestSuite.addressOf(zeroPriceFeeds[i].token);
if (token != address(0)) {
setPriceFeed(token, zeroPF);

vm.label(zeroPF, "ZERO PRICEFEED");
}
}
}
vm.label(zeroPF, "ZERO PRICEFEED");
}
}

// crvUSD PRICE FEEDS
{
CrvUsdPriceFeedData[] memory crvUSDPriceFeeds = crvUSDPriceFeedsByNetwork[chainId];
len = crvUSDPriceFeeds.length;
unchecked {
for (uint256 i; i < len; ++i) {
Tokens t = crvUSDPriceFeeds[i].token;
address token = tokenTestSuite.addressOf(t);
if (token == address(0)) continue;

address underlying = tokenTestSuite.addressOf(crvUSDPriceFeeds[i].underlying);
address pf = address(
new CurveUSDPriceFeed(
addressProvider,
token,
supportedContracts.addressOf(crvUSDPriceFeeds[i].pool),
priceFeeds[underlying],
stalenessPeriods[underlying]
)
);

setPriceFeed(token, pf);

string memory description = string(abi.encodePacked("PRICEFEED_", tokenTestSuite.symbols(t)));
vm.label(pf, description);
}
}
}

// CURVE PRICE FEEDS
// CURVE STABLE PRICE FEEDS
{
CurvePriceFeedData[] memory curvePriceFeeds = curvePriceFeedsByNetwork[chainId];
len = curvePriceFeeds.length;
Expand Down Expand Up @@ -326,7 +359,7 @@ contract PriceFeedDeployer is Test, PriceFeedDataLive {
}
}

// WSTETH_PRICE_FEED
// wstETH PRICE FEED
unchecked {
Tokens t = wstethPriceFeedByNetwork[chainId].token;
if (t != Tokens.NO_TOKEN) {
Expand Down Expand Up @@ -379,6 +412,7 @@ contract PriceFeedDeployer is Test, PriceFeedDataLive {
}
}
}

// COMPOUND V2 PRICE FEEDS
GenericLPPriceFeedData[] memory compoundV2PriceFeeds = compoundV2PriceFeedsByNetwork[chainId];
len = compoundV2PriceFeeds.length;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"dependencies": {
"@gearbox-protocol/core-v2": "^1.19.0-base.7",
"@gearbox-protocol/core-v3": "^1.30.0",
"@gearbox-protocol/sdk": "^2.1.14",
"@gearbox-protocol/sdk": "^2.1.16",
"@redstone-finance/evm-connector": "^0.2.2"
},
"devDependencies": {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1062,10 +1062,10 @@
resolved "https://registry.yarnpkg.com/@gearbox-protocol/prettier-config/-/prettier-config-1.5.0.tgz#4df8e9fd2305fee6ab8c1417a02e31343836932a"
integrity sha512-FUoprSsBdZyBjgxXCKL6mTkbeUJytaLzPJqIOoQpDmBRTX0seCc2o5I9PI9tySoRIlNnd/XXnKCXq1xHDEGbxw==

"@gearbox-protocol/sdk@^2.1.14":
version "2.1.14"
resolved "https://registry.yarnpkg.com/@gearbox-protocol/sdk/-/sdk-2.1.14.tgz#b19bfe1212ddf6f0964c45d95db297122994758c"
integrity sha512-GNTJiE3t2LVGxtUg1KLfKZtIUEL8opmtOzA0aDE1xgy/p8iuuQKU21OeLI9NT+1zBLK/yptr9wqqKtJ9bIv+XA==
"@gearbox-protocol/sdk@^2.1.16":
version "2.1.16"
resolved "https://registry.yarnpkg.com/@gearbox-protocol/sdk/-/sdk-2.1.16.tgz#68c996092cf645f750bc6e09d1685c1a8d50ba9d"
integrity sha512-u5JfNxu0j8Je0ymLFLnt2CPcXGq2WvrAMSDCcTC14tAlgowyj2zqxhYF+q8Px59D2mzwV+2MiUn/VgG6xaXCgw==
dependencies:
"@types/deep-eql" "^4.0.0"
axios "^1.2.6"
Expand Down

0 comments on commit 394d65d

Please sign in to comment.