DRAFT: Add DexOracle: indirect AMPL/USDC 24h TWAP provider#311
Open
ahnaguib wants to merge 2 commits into
Open
DRAFT: Add DexOracle: indirect AMPL/USDC 24h TWAP provider#311ahnaguib wants to merge 2 commits into
ahnaguib wants to merge 2 commits into
Conversation
No direct AMPL/USDC UniswapV2 market exists on mainnet, so this oracle bridges through WETH: AMPL/USDC = (AMPL/WETH) x (WETH/USDC), reporting an 18-decimal TWAP to a MedianOracle on the 24h rebase cadence. update() opens the measurement window right after rebase (via the Orchestrator tx list, gated to the daily update window) and pushReport() closes it ~2h before the next rebase (gated by minReportTimeIntervalSec) so the report ages past the MedianOracle security window. - contracts/DexOracle.sol: per-leg UniswapV2 cumulative-price TWAP with on-chain decimals bridging; direction is a per-leg useToken1Price flag, so no inverse code is needed. unchecked blocks faithfully mirror UniswapV2 by-design accumulator/uint32 wrapping (not expected operationally, but kept so a far-future wrap degrades gracefully instead of reverting). Constructor emits LogBridgeTokens for off-chain inspection (log-only, no revert: the two bridge-side tokens may legitimately be distinct equivalent tokens). - _external/: minimal vendored IUniswapV2Pair + 0.8.4 UniswapV2OracleLibrary. - mocks/: MockUniswapV2Pair, MockERC20Decimals, MockMedianOracle. - test/unit/DexOracle.ts: decimals bridging, chained TWAP, accumulator wraparound, window/min-period gating, and revert paths (12 tests). - scripts/deploy.ts: deploy:dexoracle task with verified mainnet pool defaults; re-reads token0()/token1() on-chain, optionally registers the provider and appends update() to the Orchestrator. Mainnet token orderings verified via eth_call: AMPL/WETH 0xc5be99... token0=WETH token1=AMPL -> price1 (WETH per AMPL) USDC/WETH 0xb4e16d... token0=USDC token1=WETH -> price1 (USDC per WETH) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
DRAFT: Add DexOracle: indirect AMPL/USDC 24h TWAP provider
🚨 Report Summary
For more details view the full report in OpenZeppelin Code Inspector |
Address review feedback: - TWAP conversion now follows the canonical fixed-window oracle: each leg's raw UQ112x112 cumulative is bridged to an 18-decimal price-seconds value at snapshot time (scale-then-diff), and the window average is the difference of two snapshots over the elapsed time. - The period gate lives only on update(); the read/consult/report path no longer carries an Uniswap-example-style PERIOD_NOT_ELAPSED check. Added a consult() view that returns the live TWAP without any timing gate. - Removed the inUpdateWindow time-of-day gating (it duplicated the MedianOracle's report-delay/expiration security window). Access control: - update(): the Orchestrator (settable, owner-managed) may call at any time; any other caller must wait `period` (default 22h = 24h rebase - 2h security delay) since the last update, preventing off-schedule window resets. - pushReport(): fully open. It can only push the honest on-chain TWAP, so it needs no gate; MedianOracle aggregation/delay handle the rest. - purgeReports(): onlyOwner (admin) passthrough to MedianOracle.purgeReports(). Tests cover the orchestrator bypass, the open pushReport, the period gate for open callers, the uint32 timestamp wraparound, decimals bridging and the purge passthrough (17 DexOracle tests; full suite 351 passing). The deploy task now calls setOrchestrator when --orchestrator is provided. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Code written by Claude seeded with a fully functional version written by me, that gets direct TWAP and pushes it to median oracle.
TODO: Encapsulate the prompt in neat way in the PR description.
No direct AMPL/USDC UniswapV2 market exists on mainnet, so this oracle bridges through WETH: AMPL/USDC = (AMPL/WETH) x (WETH/USDC), reporting an 18-decimal TWAP to a MedianOracle on the 24h rebase cadence. update() opens the measurement window right after rebase (via the Orchestrator tx list, gated to the daily update window) and pushReport() closes it ~2h before the next rebase (gated by minReportTimeIntervalSec) so the report ages past the MedianOracle security window.
TODO: Implement Purge functionality.