Skip to content

DRAFT: Add DexOracle: indirect AMPL/USDC 24h TWAP provider#311

Open
ahnaguib wants to merge 1 commit into
masterfrom
dex-oracle-2026
Open

DRAFT: Add DexOracle: indirect AMPL/USDC 24h TWAP provider#311
ahnaguib wants to merge 1 commit into
masterfrom
dex-oracle-2026

Conversation

@ahnaguib
Copy link
Copy Markdown
Contributor

@ahnaguib ahnaguib commented Jun 2, 2026

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.

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>
@openzeppelin-code
Copy link
Copy Markdown

DRAFT: Add DexOracle: indirect AMPL/USDC 24h TWAP provider

Generated at commit: b65ebb784d8fea803b5ae3f6accc4063a282fdc1

🚨 Report Summary

Severity Level Results
Contracts Critical
High
Medium
Low
Note
Total
1
1
0
5
28
35
Dependencies Critical
High
Medium
Low
Note
Total
0
0
0
0
0
0

For more details view the full report in OpenZeppelin Code Inspector

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.

1 participant