Skip to content

add OrbOracle adapter - #26

Open
sach2004 wants to merge 1 commit into
mainfrom
week7-orb-oracle-adapter
Open

add OrbOracle adapter#26
sach2004 wants to merge 1 commit into
mainfrom
week7-orb-oracle-adapter

Conversation

@sach2004

@sach2004 sach2004 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Addressed Issues:

N/A

Screenshots/Recordings:

N/A. This PR only adds an oracle adapter and tests.

Additional Notes:

This PR adds OrbOracleToOracleAdapter, which wraps an OrbOracle feed and exposes it through Gluon's IOracle interface.

Changes:

  • Added OrbOracleToOracleAdapter
  • Maps readValue() to OrbOracle readValue()
  • Maps readMaxValue() and readMinValue() using the configured sampleSize
  • Maps lastUpdated() to OrbOracle lastSubmissionTime()
  • Maps description() to OrbOracle description()
  • Scales OrbOracle values to WAD using the configured value decimals
  • Reverts on zero or negative oracle values
  • Added adapter tests for scaling, min/max, timestamp, description, and invalid values

The adapter exposes the timestamp through lastUpdated(), and the consumer can decide how to handle stale values as discussed earlier.

Local checks:

  • forge fmt
  • forge build
  • forge test

Current result:

  • 31 tests passed, 0 failed, 0 skipped

AI Usage Disclosure:

We encourage contributors to use AI tools responsibly when creating Pull Requests. While AI can be a valuable aid, it is essential to ensure that your contributions meet the task requirements, build successfully, include relevant tests, and pass all linters. Submissions that do not meet these standards may be closed without warning to maintain the quality and integrity of the project. Please take the time to understand the changes you are proposing and their impact. AI slop is strongly discouraged and may lead to banning and blocking. Do not spam our repos with AI slop.

Check one of the checkboxes below:

  • This PR does not contain AI-generated code at all.
  • This PR contains AI-generated code. I have read the AI Usage Policy and this PR complies with this policy. I have tested the code locally and I am responsible for it.

I have used the following AI models and tools: ChatGPT for planning and review. I reviewed the code myself and tested it locally with Foundry.

Checklist

  • My PR addresses a single issue, fixes a single bug or makes a single improvement.
  • My code follows the project's code style and conventions
  • If applicable, I have made corresponding changes or additions to the documentation
  • If applicable, I have made corresponding changes or additions to tests
  • My changes generate no new warnings or errors
  • I have joined the Discord server and I will share a link to this PR with the project maintainers there
  • I have read the Contribution Guidelines
  • Once I submit my PR, CodeRabbit AI will automatically review it and I will address CodeRabbit's comments.
  • I have filled this PR template completely and carefully, and I understand that my PR may be closed without review otherwise

Summary by CodeRabbit

  • New Features
    • Added an adapter to integrate Orb oracle feeds with the standard oracle interface.
    • Normalizes feed readings into a consistent 18-decimal (wad) format.
    • Supports current, min/max readings, last update timestamps, descriptions, and configurable sample sizes.
  • Bug Fixes
    • Validates feed address, rejects zero sample sizes, and disallows non-positive values from the feed.
  • Tests
    • Added a dedicated test suite covering scaling, min/max sample size behavior, metadata, and revert cases.
  • Refactor
    • Centralized wad scaling logic into a shared scaling library and reused it in the Chainlink adapter.

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 61749a8d-734c-4a9f-af71-8f8a16fdd4e1

📥 Commits

Reviewing files that changed from the base of the PR and between d7fb1f4 and c4b56d8.

📒 Files selected for processing (4)
  • src/oracles/ChainlinkToOracleAdapter.sol
  • src/oracles/OracleScalingLib.sol
  • src/oracles/OrbOracleToOracleAdapter.sol
  • test/OrbOracleAdapter.t.sol
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/OrbOracleAdapter.t.sol

📝 Walkthrough

Walkthrough

Adds OrbOracleToOracleAdapter, shared WAD scaling for oracle values, Chainlink scaling reuse, and Foundry tests covering reads, metadata, decimal conversions, sample sizes, and validation reverts.

Changes

Oracle scaling and adapter integration

Layer / File(s) Summary
Shared scaling and Chainlink integration
src/oracles/OracleScalingLib.sol, src/oracles/ChainlinkToOracleAdapter.sol
Adds shared decimal-to-WAD scaling and updates Chainlink value reads to use the library.
Orb adapter implementation
src/oracles/OrbOracleToOracleAdapter.sol
Defines the Orb feed interface, validates immutable configuration, forwards oracle reads and metadata, and scales positive signed values to WAD units.
Orb adapter validation
test/OrbOracleAdapter.t.sol
Adds a mock feed and tests scaling, sample-size forwarding, metadata passthroughs, invalid values, and constructor validation.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant OrbOracleToOracleAdapter
  participant OrbOracleInterface
  Caller->>OrbOracleToOracleAdapter: readValue()
  OrbOracleToOracleAdapter->>OrbOracleInterface: readValue()
  OrbOracleInterface-->>OrbOracleToOracleAdapter: signed value
  OrbOracleToOracleAdapter-->>Caller: scaled WAD value
Loading

Possibly related PRs

Suggested reviewers: ankitkr104

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding an OrbOracle adapter.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch week7-orb-oracle-adapter

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/oracles/OrbOracleToOracleAdapter.sol (1)

54-62: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

_scaleToWad is duplicated from ChainlinkToOracleAdapter.

The same pure function exists verbatim in src/oracles/ChainlinkToOracleAdapter.sol (lines 54–62). Extract it to a shared library to avoid divergence and ensure bug fixes apply everywhere.

♻️ Suggested shared library
// src/oracles/OracleScalingLib.sol
library OracleScalingLib {
    function scaleToWad(uint256 value, uint8 valueDecimals) internal pure returns (uint256) {
        if (valueDecimals == 18) {
            return value;
        }
        if (valueDecimals < 18) {
            return value * (10 ** (18 - uint256(valueDecimals)));
        }
        return value / (10 ** (uint256(valueDecimals) - 18));
    }
}

Then in both adapters:

+import {OracleScalingLib} from "./OracleScalingLib.sol";
 ...
-    function _scaleToWad(uint256 value, uint8 decimals) internal pure returns (uint256) {
-        if (decimals == 18) {
-            return value;
-        }
-        if (decimals < 18) {
-            return value * (10 ** (18 - uint256(decimals)));
-        }
-        return value / (10 ** (uint256(decimals) - 18));
-    }
+    using OracleScalingLib for uint256;

And update call sites to value.scaleToWad(valueDecimals) or OracleScalingLib.scaleToWad(value, valueDecimals).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/oracles/OrbOracleToOracleAdapter.sol` around lines 54 - 62, Extract the
duplicated scaling logic from _scaleToWad in OrbOracleToOracleAdapter and its
counterpart in ChainlinkToOracleAdapter into a shared
OracleScalingLib.scaleToWad function. Import the library in both adapters,
replace all existing _scaleToWad call sites with the shared function, and remove
the duplicated internal helper methods.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/oracles/OrbOracleToOracleAdapter.sol`:
- Around line 54-62: Extract the duplicated scaling logic from _scaleToWad in
OrbOracleToOracleAdapter and its counterpart in ChainlinkToOracleAdapter into a
shared OracleScalingLib.scaleToWad function. Import the library in both
adapters, replace all existing _scaleToWad call sites with the shared function,
and remove the duplicated internal helper methods.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 55912c4e-e06a-4e7f-b4d9-d52fa80c4843

📥 Commits

Reviewing files that changed from the base of the PR and between 1623875 and d7fb1f4.

📒 Files selected for processing (2)
  • src/oracles/OrbOracleToOracleAdapter.sol
  • test/OrbOracleAdapter.t.sol

@sach2004
sach2004 force-pushed the week7-orb-oracle-adapter branch from d7fb1f4 to c4b56d8 Compare July 10, 2026 10:13
@sach2004

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@sach2004
sach2004 requested a review from ankitkr104 July 10, 2026 10:16
@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@ankitkr104 ankitkr104 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my side it is Good to go

@sach2004

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

function description() external view returns (string memory);
}

contract OrbOracleToOracleAdapter is IOracle {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't need an adapter for orb oracles. Instead, by having Gluon and Orb agreeing on the oracle interface, Gluon should be able to use Orb oracles directly.

It seems that there are two disagreements that are forcing you to implement this adapter:

1 - Orb is returning int256 but Gluon is expecting uint256.

2 - Orb has a configurable number of decimals, but Gluon is expecting 18 decimals.

To solve 2, let's make Orb always use 18 decimals too.

To solve 2, let's make Orb always return uint256.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants