Verified contractPartialMIT
NAVFeed
Address0xd8bfd76dbf6977b1fc7c47269bf47fb3e6a8375f
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.8.30
- Same code
1 more contract
Details
- Compiler
- solc 0.8.30+commit.73712a01
- Language
- solidity
- Optimization
- Yes, 500 runs
- EVM version
- shanghai
- Via IR
- yes
- License
- MIT
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,494,356
- Creation transaction
- 0x504f104034…4a181a43be
4 files
src/nav/feed/NAVFeed.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.30;
import {AggregatorV3Interface} from "../../external/AggregatorV3Interface.sol";
import {INAVOracle} from "../interfaces/INAVOracle.sol";
/**
* @title NAVFeed — integrator-facing AggregatorV3 façade
* @notice View-only adapter exposing a {NAVOracle} core as a Chainlink-style feed. It has no
* privileged functions or post-deployment state changes. Feed semantics such as decimals,
* description, and round mapping can be changed by deploying a new adapter and selecting it
* through {NAVFeedProxy}, without changing the oracle core or its state.
*
* @dev During Protection Mode, provider reports and force updates cannot create rounds, but a
* timelocked markdown can. Integrators should therefore check protection state directly rather
* than relying only on `updatedAt` becoming stale.
*
* @dev Construction verifies that the core reports 18 NAV decimals. Answers are scaled down to
* {decimals} (8 by convention) using integer division. No precision is discarded when
* `decimals` is 18.
*/
contract NAVFeed is AggregatorV3Interface {
/// @notice The core oracle this feed reads.
INAVOracle public immutable oracle;
/// @notice Feed decimals. `AnswerUpdated` and `NewRound` are emitted by the oracle core, not
/// this view-only adapter.
uint8 public immutable decimals;
/// @dev 10**(18 - decimals): divisor scaling protocol NAV to feed answers.
uint256 private immutable _scale;
string private _description;
error InvalidDecimals(uint8 decimals);
error InvalidCoreDecimals(uint8 decimals);
error ZeroAddress();
error NotAContract(address oracle);
constructor(address oracle_, uint8 decimals_, string memory description_) {
if (oracle_ == address(0)) revert ZeroAddress();
if (oracle_.code.length == 0) revert NotAContract(oracle_);
uint8 coreDecimals = INAVOracle(oracle_).navDecimals();
if (coreDecimals != 18) revert InvalidCoreDecimals(coreDecimals);
// Below 6 decimals, MIN_MARKDOWN_NAV (1e12 at 18 decimals) scales to zero. Six decimals
// keeps every permitted NAV positive on this feed; eight is the conventional setting.
if (decimals_ < 6 || decimals_ > 18) revert InvalidDecimals(decimals_);
oracle = INAVOracle(oracle_);
decimals = decimals_;
_scale = 10 ** (18 - decimals_);
_description = description_;
}
/// @notice Human-readable feed description.
function description() external view returns (string memory) {
return _description;
}
// Incident and data-time passthroughs. NAVFeedProxy does not expose these custom methods, so a
// caller starting from the proxy must first resolve its current adapter.
/// @notice Whether the core is in Protection Mode. A markdown can refresh `updatedAt` while
/// protection remains active, so integrators should check this value directly.
function protectionMode() external view returns (bool) {
return oracle.protectionMode();
}
/// @notice Protection episode id; increments on each entry and binds markdowns to that entry.
function protectionEpisodeId() external view returns (uint256) {
return oracle.protectionEpisodeId();
}
/// @notice Source-data timestamp associated with the current NAV. Bootstrap and reports retain
/// their source observation time; force updates and markdowns use their execution time.
/// `latestRoundData().updatedAt` remains the block time the round was recorded.
function latestObservationTimestamp() external view returns (uint256) {
return oracle.currentDataTimestamp();
}
/// @notice Feed implementation version.
function version() external pure returns (uint256) {
return 1;
}
/// @notice Latest round, scaled to the feed's configured decimals.
/// @dev `startedAt` and `updatedAt` both report when the core recorded the round, not the
/// source observation time. Use {latestObservationTimestamp} for the latter.
function latestRoundData()
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
)
{
return _roundData(oracle.latestRound());
}
/// @notice A stored round, scaled to the feed's configured decimals.
/// @dev `startedAt` and `updatedAt` both report when the core recorded the round, not the
/// source observation time. The call reverts when `_roundId` does not exist.
function getRoundData(uint80 _roundId)
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
)
{
return _roundData(_roundId);
}
// NAVFeed implements only the V3 surface. NAVFeedProxy derives its V2 getters from these V3
// reads, keeping both interfaces consistent for callers of the proxy.
function _roundData(uint80 roundId_)
private
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
)
{
// The oracle reverts NoData when the requested round does not exist.
(uint256 nav, uint256 roundUpdatedAt) = oracle.getRound(roundId_);
return (roundId_, int256(nav / _scale), roundUpdatedAt, roundUpdatedAt, roundId_);
}
}
src/external/AggregatorV3Interface.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.30;
interface AggregatorV3Interface {
function decimals() external view returns (uint8);
function description() external view returns (string memory);
function version() external view returns (uint256);
function getRoundData(uint80 _roundId)
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
);
function latestRoundData()
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
);
}
src/nav/interfaces/INAVDataProvider.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.30;
/**
* @title NAV Data Provider Interface
* @notice Minimal read surface for a NAV value and its source-data timestamp.
*/
interface INAVDataProvider {
/**
* @notice Return the current NAV and the time its source data was observed.
* @return nav The latest NAV value with 18 decimal places.
* @return timestamp The source observation time in Unix seconds. An intermediary must preserve
* this value rather than replace it with its own acceptance time.
*/
function getCurrentNAV() external view returns (uint256 nav, uint256 timestamp);
}
src/nav/interfaces/INAVOracle.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.30;
import {INAVDataProvider} from "./INAVDataProvider.sol";
/// @notice How an accepted NAV round was produced. Emitted with every round for monitoring/audit.
enum UpdateKind {
Bootstrap, // initial seed recorded by the NAVOracle constructor
Report, // automated up-or-flat write submitted through an authorized provider
Force, // authorized manual up-or-flat write for outage or recovery use
Markdown // delayed write-down; the only NAVOracle path that can decrease NAV
}
/// @notice Outcome of a {INAVOracle.submitReport} call.
/// @dev NAVOracle returns a status for accepted reports and terminal no-write outcomes; future-dated
/// observations and value-rail violations revert. Report providers are expected to treat a
/// returned status as transport success, but that mapping is provider behavior.
enum SubmitStatus {
Accepted,
IgnoredInProtection,
DiscardedNonMonotonic,
DiscardedStale
}
// ----- Shared events (file-level so NAVOracle and its report providers use one set of
// declarations without inheritance) -----
/// @notice A new NAV round was accepted (any path — see kind).
event NAVUpdated(
uint80 indexed roundId, uint256 nav, uint256 observationTimestamp, UpdateKind kind
);
/// @notice Chainlink V2 event signatures emitted by NAVOracle when it records a core round.
/// @dev `AnswerUpdated.current` is the raw 18-decimal core NAV, and the log emitter is NAVOracle.
/// It is not a scaled feed answer: for example, an 8-decimal NAVFeed returns
/// `floor(current / 1e10)` as `latestRoundData().answer`, while an 8-decimal NAVFeedProxy
/// returns that value from both `latestAnswer()` and `latestRoundData().answer`.
event AnswerUpdated(int256 indexed current, uint256 indexed roundId, uint256 updatedAt);
event NewRound(uint256 indexed roundId, address indexed startedBy, uint256 startedAt);
/// @notice A provider report arrived during Protection Mode and was ignored. The returned status
/// can be mapped to transport acknowledgement by the provider.
event ReportIgnoredInProtection(bytes32 indexed feedId, uint256 nav, uint256 observationTimestamp);
/// @notice A non-monotonic or stale provider observation was discarded.
/// @dev NAVOracle returns a discard status; transport retry behavior belongs to the provider.
event ReportDiscarded(
bytes32 indexed feedId, uint256 nav, uint256 observationTimestamp, bytes4 reason
);
/// @notice An accepted provider report was written.
event ReportAccepted(
bytes32 indexed feedId, uint256 nav, uint256 observationTimestamp, uint256 deviationBps
);
/// @notice Protection Mode entered (`by` is the enterer; every entry consumes the one-shot arming).
event ProtectionModeEntered(address indexed by, uint256 indexed episodeId, string reason);
/// @notice Protection Mode exited by an authorized caller.
event ProtectionModeExited(address indexed by);
/// @notice Protection entry was re-armed by an authorized caller.
event ProtectionEntryRearmed(address indexed by);
/// @notice A timelocked markdown executed: NAV decreased from previousNav to newNav.
event MarkdownApplied(uint80 indexed roundId, uint256 previousNav, uint256 newNav, string reason);
/// @notice Authorized manual up-or-flat write.
event NAVForceUpdated(address indexed by, uint256 nav, uint256 observationTimestamp, string reason);
/// @notice Constructor seed recorded as round 1 (no sink push).
event Bootstrapped(address indexed deployer, uint256 nav, uint256 dataTimestamp);
// Configuration events.
event NormalBandUpdated(uint256 previous, uint256 current);
event ForceBandUpdated(uint256 previous, uint256 current);
event MaxNAVUpdated(uint256 previous, uint256 current);
// ----- Shared errors (file-level for the same reason) -----
error ZeroAddress();
error ZeroFeedId();
error InvalidBounds();
error InvalidBand();
error InvalidVelocity();
error InvalidStaleness();
error NoData(uint80 roundId);
/// @dev Used as the {ReportDiscarded} reason selector for a non-monotonic observation; the
/// submission returns a discard status instead of reverting with this error.
error NonMonotonicObservation(uint256 observationTimestamp, uint256 lastObservationTs);
error ZeroObservationTimestamp();
error FutureObservation(uint256 observationTimestamp, uint256 blockTimestamp);
error StaleObservation(uint256 observationTimestamp);
error OutOfBounds(uint256 navValue);
error DeviationExceeded(uint256 navValue, uint256 currentNav, uint256 deviationBps);
error VelocityExceeded(uint256 navValue, uint256 moveWad, uint256 budgetWad);
error NAVMustNotDecrease(uint256 navValue, uint256 currentNav);
error ProtectionModeActive();
error ProtectionModeNotActive();
error ProtectionEntryNotArmed();
error MarkdownMustDecrease(uint256 navValue, uint256 currentNav);
error MarkdownBelowFloor(uint256 navValue, uint256 floor);
error MarkdownEpisodeMismatch(uint256 providedEpisode, uint256 currentEpisode);
error MarkdownTooFrequent(uint256 elapsed, uint256 required);
error MarkdownDelayNotElapsed(uint256 readyAt, uint256 nowTs);
error InvalidMarkdownDelay();
error ForceUpdateTooFrequent(uint256 elapsed, uint256 required);
/**
* @title INAVOracle
* @notice Protocol-facing surface implemented by {NAVOracle}. NAV uses 18-decimal fixed-point units
* on this surface; an integrator-facing feed may scale values to different decimals.
*
* @dev NAVOracle ignores automated reports and blocks force writes during Protection Mode, while
* delayed markdowns remain available. If no markdown executes, the latest round timestamp
* remains unchanged. AccessManager scheduling and any market action triggered by feed
* staleness are deployment and integrator policy rather than guarantees of this interface.
*/
interface INAVOracle is INAVDataProvider {
/// @notice Number of decimals used by the protocol NAV surface.
/// @dev NAVOracle returns 18. The distinct name avoids confusing protocol NAV decimals with an
/// AggregatorV3 feed's `decimals()`.
function navDecimals() external pure returns (uint8);
/// @notice Latest accepted round id (at least 1 because the constructor records the seed).
function latestRound() external view returns (uint80);
/// @notice Return a stored round. NAVOracle reverts {NoData} for a nonexistent round id.
function getRound(uint80 roundId) external view returns (uint256 answer, uint256 updatedAt);
/// @notice Whether Protection Mode is active.
/// @dev NAVOracle ignores reports and blocks force writes while active; markdowns remain
/// available subject to their episode and timing gates.
function protectionMode() external view returns (bool);
/// @notice Monotonically increasing protection episode id used to bind NAVOracle markdowns.
function protectionEpisodeId() external view returns (uint256);
/// @notice Source-data timestamp associated with the current NAV value.
/// @dev Bootstrap and reports preserve their source observation time; force writes and
/// markdowns use their execution block time. This is distinct from a round's `updatedAt`,
/// which records when this oracle accepted the round. It can move backward when a report
/// observed shortly before a force write is accepted afterward.
function currentDataTimestamp() external view returns (uint256);
/// @notice Timestamp used only for automated-report ordering and replay protection.
/// @dev NAVOracle initializes it from the constructor seed's source-data timestamp. Accepted
/// reports and markdowns advance it; force writes do not. It is not necessarily the
/// timestamp associated with the current NAV value; use {currentDataTimestamp} for that.
function lastObservationTs() external view returns (uint256);
/// @notice The feed identifier this oracle serves (report providers bind against it).
function feedId() external view returns (bytes32);
/// @notice Submit a NAV observation to the implementing oracle.
/// @dev NAVOracle restricts this call through its authority and enforces its value and ordering
/// rails. Transport authentication, decoding, and chain/feed binding remain provider
/// responsibilities; provider authorization is deployment wiring.
/// @param navValue NAV in 18-decimal fixed-point units.
/// @param observationTimestamp Observation time in Unix seconds.
/// @return status Accepted or terminal no-write outcome.
function submitReport(uint256 navValue, uint256 observationTimestamp)
external
returns (SubmitStatus);
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"libraries": {},
"optimizer": {
"runs": 500,
"enabled": true
},
"evmVersion": "shanghai",
"remappings": [
"@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"@openzeppelin/[email protected]/=lib/openzeppelin-contracts/contracts/",
"forge-std/=lib/forge-std/src/",
"@chainlink/local/=lib/chainlink-local/",
"@chainlink/contracts-ccip/contracts/=lib/chainlink-local/lib/chainlink-ccip/chains/evm/contracts/",
"@chainlink/contracts-ccip/interfaces/=lib/chainlink-local/lib/chainlink-ccip/chains/evm/contracts/interfaces/",
"@chainlink/contracts-ccip/libraries/=lib/chainlink-local/lib/chainlink-ccip/chains/evm/contracts/libraries/",
"@chainlink/contracts-ccip/applications/=lib/chainlink-local/lib/chainlink-ccip/chains/evm/contracts/applications/",
"solady/=lib/solady/src/",
"@chainlink/=lib/chainlink/",
"@openzeppelin/foundry-upgrades/=lib/openzeppelin-foundry-upgrades/src/",
"openzeppelin-foundry-upgrades/=lib/openzeppelin-foundry-upgrades/src/",
"@openzeppelin/[email protected]/=lib/chainlink-local/src/vendor/openzeppelin-solidity/v4.7.3/contracts/",
"@openzeppelin/[email protected]/=lib/chainlink-local/src/vendor/openzeppelin-solidity/v4.8.3/contracts/",
"chainlink-ccip/=lib/chainlink-local/lib/chainlink-ccip/chains/evm/contracts/vendor/optimism/interop-lib/v0/src/",
"chainlink-evm/=lib/chainlink-local/lib/chainlink-evm/",
"chainlink-local/=lib/chainlink-local/src/",
"chainlink/=lib/chainlink/",
"ds-test/=lib/morpho-blue/lib/forge-std/lib/ds-test/src/",
"erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
"halmos-cheatcodes/=lib/openzeppelin-contracts-upgradeable/lib/halmos-cheatcodes/src/",
"morpho-blue/=lib/morpho-blue/",
"openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"pendle-core-v2-public/=lib/pendle-core-v2-public/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.