Skip to content
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
59 changes: 59 additions & 0 deletions contracts/helpers/ConstantPriceFeed.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// SPDX-License-Identifier: GPL-2.0-or-later
// Gearbox Protocol. Generalized leverage for DeFi protocols
// (c) Gearbox Foundation, 2025.
pragma solidity ^0.8.23;

import {LibString} from "@solady/utils/LibString.sol";
import {IPriceFeed} from "@gearbox-protocol/core-v3/contracts/interfaces/base/IPriceFeed.sol";
import {SanityCheckTrait} from "@gearbox-protocol/core-v3/contracts/traits/SanityCheckTrait.sol";
import {IncorrectPriceException} from "@gearbox-protocol/core-v3/contracts/interfaces/IExceptions.sol";
import {AP_CONSTANT_PRICE_FEED} from "../libraries/ContractLiterals.sol";

/// @title Constant price feed
/// @notice A simple price feed that returns a constant value set in the constructor
contract ConstantPriceFeed is IPriceFeed, SanityCheckTrait {
using LibString for string;
using LibString for bytes32;

/// @notice Contract version
uint256 public constant override version = 3_10;

/// @notice Contract type
bytes32 public constant override contractType = AP_CONSTANT_PRICE_FEED;

/// @notice Answer precision (always 8 decimals for USD price feeds)
uint8 public constant override decimals = 8;

/// @notice Indicates that price oracle can skip checks for this price feed's answers
bool public constant override skipPriceCheck = true;

/// @notice The constant price value to return
int256 public immutable price;

bytes32 internal descriptionTicker;

/// @notice Constructor
/// @param _price The constant price value to return (with 8 decimals)
/// @param _descriptionTicker Short form description
constructor(int256 _price, string memory _descriptionTicker) {
if (_price <= 0) revert IncorrectPriceException();

price = _price;
descriptionTicker = _descriptionTicker.toSmallString();
}

/// @notice Price feed description
function description() external view override returns (string memory) {
return string.concat(descriptionTicker.fromSmallString(), " constant price feed");
}

/// @notice Serialized price feed parameters
function serialize() external view override returns (bytes memory) {
return abi.encode(price);
}

/// @notice Returns the constant USD price of the token with 8 decimals
function latestRoundData() external view override returns (uint80, int256 answer, uint256, uint256, uint80) {
return (0, price, 0, block.timestamp, 0);
}
}
40 changes: 0 additions & 40 deletions contracts/helpers/DefaultLossPolicy.sol

This file was deleted.

2 changes: 1 addition & 1 deletion contracts/libraries/ContractLiterals.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ bytes32 constant AP_ACL = "ACL";
bytes32 constant AP_ADDRESS_PROVIDER = "ADDRESS_PROVIDER";
bytes32 constant AP_BOT_LIST = "BOT_LIST";
bytes32 constant AP_BYTECODE_REPOSITORY = "BYTECODE_REPOSITORY";
bytes32 constant AP_CONSTANT_PRICE_FEED = "PRICE_FEED::CONSTANT";
bytes32 constant AP_CONTRACTS_REGISTER = "CONTRACTS_REGISTER";
bytes32 constant AP_CREDIT_CONFIGURATOR = "CREDIT_CONFIGURATOR";
bytes32 constant AP_CREDIT_FACADE = "CREDIT_FACADE";
Expand All @@ -28,7 +29,6 @@ bytes32 constant AP_INTEREST_RATE_MODEL_DEFAULT = "IRM::DEFAULT";
bytes32 constant AP_INTEREST_RATE_MODEL_FACTORY = "INTEREST_RATE_MODEL_FACTORY";
bytes32 constant AP_INTEREST_RATE_MODEL_LINEAR = "IRM::LINEAR";
bytes32 constant AP_LOSS_POLICY_ALIASED = "LOSS_POLICY::ALIASED";
bytes32 constant AP_LOSS_POLICY_DEFAULT = "LOSS_POLICY::DEFAULT";
bytes32 constant AP_LOSS_POLICY_FACTORY = "LOSS_POLICY_FACTORY";
bytes32 constant AP_MARKET_CONFIGURATOR = "MARKET_CONFIGURATOR";
bytes32 constant AP_MARKET_CONFIGURATOR_FACTORY = "MARKET_CONFIGURATOR_FACTORY";
Expand Down
Loading