DRAFT: Add DexOracle: indirect AMPL/USDC 24h TWAP provider#311
Open
ahnaguib wants to merge 1 commit into
Open
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 |
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.