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: minor fixes #49

Merged
merged 3 commits into from
Jul 24, 2024
Merged
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
8 changes: 8 additions & 0 deletions contracts/interfaces/mellow/IMellowChainlinkOracle.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: MIT
// Gearbox Protocol. Generalized leverage for DeFi protocols
// (c) Gearbox Foundation, 2024.
pragma solidity ^0.8.23;

interface IMellowChainlinkOracle {
function baseTokens(address vault) external view returns (address);
}
4 changes: 4 additions & 0 deletions contracts/interfaces/mellow/IMellowVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// (c) Gearbox Foundation, 2024.
pragma solidity ^0.8.23;

import {IMellowVaultConfigurator} from "./IMellowVaultConfigurator.sol";

interface IMellowVault {
struct ProcessWithdrawalsStack {
address[] tokens;
Expand All @@ -17,4 +19,6 @@ interface IMellowVault {
}

function calculateStack() external view returns (ProcessWithdrawalsStack memory s);

function configurator() external view returns (IMellowVaultConfigurator);
}
10 changes: 10 additions & 0 deletions contracts/interfaces/mellow/IMellowVaultConfigurator.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT
// Gearbox Protocol. Generalized leverage for DeFi protocols
// (c) Gearbox Foundation, 2024.
pragma solidity ^0.8.23;

import {IMellowChainlinkOracle} from "./IMellowChainlinkOracle.sol";

interface IMellowVaultConfigurator {
function priceOracle() external view returns (IMellowChainlinkOracle);
}
2 changes: 1 addition & 1 deletion contracts/oracles/balancer/BPTStablePriceFeed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {IBalancerStablePool} from "../../interfaces/balancer/IBalancerStablePool
/// @dev Similarly to Curve stableswap, aggregate function is minimum of underlying tokens prices
contract BPTStablePriceFeed is LPPriceFeed {
uint256 public constant override version = 3_10;
bytes32 public constant contractType = "PF_BALANCER_STABLE_LP_ORACLE";
bytes32 public constant override contractType = "PF_BALANCER_STABLE_LP_ORACLE";

uint8 public immutable numAssets;

Expand Down
2 changes: 1 addition & 1 deletion contracts/oracles/balancer/BPTWeightedPriceFeed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ contract BPTWeightedPriceFeed is LPPriceFeed {
using FixedPoint for uint256;

uint256 public constant override version = 3_10;
bytes32 public constant contractType = "PF_BALANCER_WEIGHTED_LP_ORACLE";
bytes32 public constant override contractType = "PF_BALANCER_WEIGHTED_LP_ORACLE";

/// @notice Balancer vault address
address public immutable vault;
Expand Down
2 changes: 1 addition & 1 deletion contracts/oracles/curve/CurveCryptoLPPriceFeed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ contract CurveCryptoLPPriceFeed is LPPriceFeed {
using FixedPoint for uint256;

uint256 public constant override version = 3_10;
bytes32 public constant contractType = "PF_CURVE_CRYPTO_LP_ORACLE";
bytes32 public constant override contractType = "PF_CURVE_CRYPTO_LP_ORACLE";

uint16 public immutable nCoins;

Expand Down
10 changes: 2 additions & 8 deletions contracts/oracles/mellow/MellowLRTPriceFeed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,10 @@ contract MellowLRTPriceFeed is SingleAssetLPPriceFeed {
/// @dev Amount of base token comprising a single unit (accounting for decimals)
uint256 immutable _baseTokenUnit;

constructor(
address _acl,
uint256 lowerBound,
address _vault,
address _priceFeed,
uint32 _stalenessPeriod,
address baseToken
)
constructor(address _acl, uint256 lowerBound, address _vault, address _priceFeed, uint32 _stalenessPeriod)
SingleAssetLPPriceFeed(_acl, _vault, _vault, _priceFeed, _stalenessPeriod) // U:[MEL-1]
{
address baseToken = IMellowVault(_vault).configurator().priceOracle().baseTokens(_vault);
_baseTokenUnit = 10 ** ERC20(baseToken).decimals();
_setLimiter(lowerBound); // U:[MEL-1]
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/oracles/updatable/PythPriceFeed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ contract PythPriceFeed is IUpdatablePriceFeed {
// --------------- //

uint256 public constant override version = 3_10;
bytes32 public constant contractType = "PF_PYTH_ORACLE";
bytes32 public constant override contractType = "PF_PYTH_ORACLE";

uint8 public constant override decimals = 8;
bool public constant override skipPriceCheck = false;
Expand Down
19 changes: 10 additions & 9 deletions contracts/oracles/updatable/RedstonePriceFeed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,14 @@ contract RedstonePriceFeed is IUpdatablePriceFeed, RedstoneConsumerNumericBase {
/// @notice Thrown when the provided set of signers contains duplicates
error DuplicateSignersException();

/// @notice Thrown when attempting to push an update with the payload that is older than the last
/// update payload, or too far from the current block timestamp
error RedstonePayloadTimestampIncorrect();
/// @notice Thrown when expected payload timestamp is too far ahead in the future
error PayloadTimestampTooFarAheadException();

/// @notice Thrown when expected payload timestamp is too far behind in the past
error PayloadTimestampTooFarBehindException();

/// @notice Thrown when data package timestamp is not equal to expected payload timestamp
error DataPackageTimestampIncorrect();
error IncorrectDataPackageTimestampException();

// ----------- //
// CONSTRUCTOR //
Expand Down Expand Up @@ -223,20 +225,19 @@ contract RedstonePriceFeed is IUpdatablePriceFeed, RedstoneConsumerNumericBase {
uint256 receivedTimestampSeconds = receivedTimestampMilliseconds / 1000;

if (receivedTimestampSeconds != lastPayloadTimestamp) {
revert DataPackageTimestampIncorrect(); // U:[RPF-3]
revert IncorrectDataPackageTimestampException(); // U:[RPF-3]
}
}

/// @dev Validates that the expected payload timestamp is not older than the last payload's,
/// and not too far from the current block's
/// @dev Validates that the expected payload timestamp is not too far ahead or behind of the current block timestamp
/// @param expectedPayloadTimestamp Timestamp expected to be in all of the incoming payload's packages
function _validateExpectedPayloadTimestamp(uint256 expectedPayloadTimestamp) internal view {
if ((block.timestamp < expectedPayloadTimestamp)) {
if ((expectedPayloadTimestamp - block.timestamp) > MAX_DATA_TIMESTAMP_AHEAD_SECONDS) {
revert RedstonePayloadTimestampIncorrect(); // U:[RPF-9]
revert PayloadTimestampTooFarAheadException(); // U:[RPF-9]
}
} else if ((block.timestamp - expectedPayloadTimestamp) > MAX_DATA_TIMESTAMP_DELAY_SECONDS) {
revert RedstonePayloadTimestampIncorrect(); // U:[RPF-9]
revert PayloadTimestampTooFarBehindException(); // U:[RPF-9]
}
}
}
14 changes: 14 additions & 0 deletions contracts/test/mocks/mellow/MellowChainlinkOracleMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: UNLICENSED
// Gearbox Protocol. Generalized leverage for DeFi protocols
// (c) Gearbox Foundation, 2024.
pragma solidity ^0.8.23;

import {IMellowChainlinkOracle} from "../../../interfaces/mellow/IMellowChainlinkOracle.sol";

contract MellowChainlinkOracleMock is IMellowChainlinkOracle {
mapping(address vault => address) public baseTokens;

function setBaseToken(address vault, address baseToken) external {
baseTokens[vault] = baseToken;
}
}
15 changes: 15 additions & 0 deletions contracts/test/mocks/mellow/MellowVaultConfiguratorMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: UNLICENSED
// Gearbox Protocol. Generalized leverage for DeFi protocols
// (c) Gearbox Foundation, 2024.
pragma solidity ^0.8.23;

import {IMellowChainlinkOracle} from "../../../interfaces/mellow/IMellowChainlinkOracle.sol";
import {IMellowVaultConfigurator} from "../../../interfaces/mellow/IMellowVaultConfigurator.sol";

contract MellowVaultConfiguratorMock is IMellowVaultConfigurator {
IMellowChainlinkOracle public priceOracle;

constructor(IMellowChainlinkOracle priceOracle_) {
priceOracle = priceOracle_;
}
}
7 changes: 6 additions & 1 deletion contracts/test/mocks/mellow/MellowVaultMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
pragma solidity ^0.8.23;

import {IMellowVault} from "../../../interfaces/mellow/IMellowVault.sol";
import {IMellowVaultConfigurator} from "../../../interfaces/mellow/IMellowVaultConfigurator.sol";

contract MellowVaultMock is IMellowVault {
IMellowVault.ProcessWithdrawalsStack stack;

constructor() {}
IMellowVaultConfigurator public configurator;

constructor(IMellowVaultConfigurator configurator_) {
configurator = configurator_;
}

function setStack(uint256 totalValue, uint256 totalSupply) external {
stack.totalValue = totalValue;
Expand Down
3 changes: 1 addition & 2 deletions contracts/test/suites/PriceFeedDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -664,8 +664,7 @@ contract PriceFeedDeployer is Test, PriceFeedDataLive {
lowerBound,
token,
_getDeployedFeed(underlying, mellowLRTPriceFeeds[i].reserve),
_getDeployedStalenessPeriod(underlying, mellowLRTPriceFeeds[i].reserve),
underlying
_getDeployedStalenessPeriod(underlying, mellowLRTPriceFeeds[i].reserve)
)
);

Expand Down
11 changes: 9 additions & 2 deletions contracts/test/unit/mellow/MellowLRTPriceFeed.unit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import {IMellowVault} from "../../../interfaces/mellow/IMellowVault.sol";

import {PriceFeedUnitTestHelper} from "../PriceFeedUnitTestHelper.sol";

import {MellowChainlinkOracleMock} from "../../mocks/mellow/MellowChainlinkOracleMock.sol";
import {MellowVaultMock} from "../../mocks/mellow/MellowVaultMock.sol";
import {MellowVaultConfiguratorMock} from "../../mocks/mellow/MellowVaultConfiguratorMock.sol";
import {ERC20Mock} from "@gearbox-protocol/core-v3/contracts/test/mocks/token/ERC20Mock.sol";

import {MellowLRTPriceFeed} from "../../../oracles/mellow/MellowLRTPriceFeed.sol";
Expand All @@ -23,10 +25,15 @@ contract MellowLRTPriceFeedUnitTest is PriceFeedUnitTestHelper {
_setUp();

asset = new ERC20Mock("Test Token", "TEST", 18);
vault = new MellowVaultMock();

MellowChainlinkOracleMock chainlinkOracle = new MellowChainlinkOracleMock();
MellowVaultConfiguratorMock vaultConfigurator = new MellowVaultConfiguratorMock(chainlinkOracle);
vault = new MellowVaultMock(vaultConfigurator);
vault.setStack(1.2e18, 1e18);
chainlinkOracle.setBaseToken(address(vault), address(asset));

priceFeed = new MellowLRTPriceFeed(
address(addressProvider), 1.2e18, address(vault), address(underlyingPriceFeed), 1 days, address(asset)
address(addressProvider), 1.2e18, address(vault), address(underlyingPriceFeed), 1 days
);
}

Expand Down
6 changes: 3 additions & 3 deletions contracts/test/unit/updatable/RedstonePriceFeed.unit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ contract RedstonePriceFeedUnitTest is TestHelper, RedstoneConstants {

bytes memory data = abi.encode(expectedPayloadTimestamp, payload);

vm.expectRevert(RedstonePriceFeed.DataPackageTimestampIncorrect.selector);
vm.expectRevert(RedstonePriceFeed.IncorrectDataPackageTimestampException.selector);

pf.updatePrice(data);
}
Expand Down Expand Up @@ -264,7 +264,7 @@ contract RedstonePriceFeedUnitTest is TestHelper, RedstoneConstants {

bytes memory data = abi.encode(expectedPayloadTimestamp, payload);

vm.expectRevert(RedstonePriceFeed.RedstonePayloadTimestampIncorrect.selector);
vm.expectRevert(RedstonePriceFeed.PayloadTimestampTooFarBehindException.selector);

pf.updatePrice(data);

Expand All @@ -276,7 +276,7 @@ contract RedstonePriceFeedUnitTest is TestHelper, RedstoneConstants {

data = abi.encode(expectedPayloadTimestamp, payload);

vm.expectRevert(RedstonePriceFeed.RedstonePayloadTimestampIncorrect.selector);
vm.expectRevert(RedstonePriceFeed.PayloadTimestampTooFarAheadException.selector);

pf.updatePrice(data);
}
Expand Down
Loading