This proposal is to upgrade the Compound II UniswapAnchoredView (UAV) Oracle. The upgrade will update the UAV’s reference prices from Uniswap V2 pools to Uniswap V3 pools.
Note that this proposal references the CIP-style format.
A significant amount of liquidity on Uniswap V2 has shifted towards Uniswap V3 as liquidity providers capitalize on concentrated liquidity provisioning strategies. Compound’s UAV Oracle, which serves as a reference anchor mechanism for pricing data ingestion, must follow this shift of market liquidity to provide higher reliability and security assurances by reducing the risk of price manipulation or other issues related to low liquidity. This proposal aims to address this by updating the UAV to check the prices on Uniswap V3 instead of Uniswap V2.
Below are details that have stayed the same from the original proposal.
- The new UniswapAnchoredView (UAV) no longer records and keeps observations but instead queries the respective Uniswap V3 pool’s observe function to get a TWAP with the set anchor period when it’s needed (i.e., when a reporter calls validate on the UAV).
- The price of an asset in Uniswap V3 is a function of the “tick” of the pool. The formula is price = 1.0001^tick. The math required for conversion between posted prices and the Uniswap V3 TWAP and the UAV representation has been modified to support this. Relevant libraries (TickMath and FullMath) have been included from the Uniswap V3 codebase.
- The tests from the original UAV have been adapted to the new Uniswap V3 architecture - i.e., observations/TWAP tests were removed. Hardhat (+typechain) has been implemented so real Uniswap V3 pools can be used via forked mainnet in tests and eliminate the need for mocking Uniswap V3 pools.
- Increased the Uniswap observation cardinality to 150 on pools that were below 150. “cardinality” in Uniswap is a term for the TWAP lookback history. It represents the state changes per block, so ten trades in a block get condensed and recorded as one update in the lookback. To save on gas costs, the cardinality starts at 2, and anyone can pay the gas cost for a deeper lookback. Therefore, increasing the cardinality to 150 ensures a safe minimum for the lookback history.
We note that a reduction in liquidity within Uniswap v3 pools can make the TWAP price in those pools easier to manipulate and may cause the Uniswap anchor to be less accurate than expected. However, this will not affect the accuracy of the primary Price Feeds from Chainlink.
Notably, the main change from the last implementation is to update the getUnderlyingPrice function to fetch the token configuration using the cToken address instead of calling the underlying function from the cToken. The reasoning is that getUnderlyingPrice fails when passing in the address of the cETH token as cETH does not implement the underlying function like other cTokens. The community can review this change in PR14 in Github.
The new UAV3 contract is deployed here, which matches the changes from PR14 outlined above. We encourage the community to inspect this instance and provide any feedback.
The rationale behind the proposed design goes back to when the UAV was initially created. After the DAI liquidation event, in which the Coinbase oracle deviated from the market-wide price for DAI/USD, the Compound community came to a consensus to upgrade Compound II’s oracle system to use Chainlink Price Feeds. The community had also determined to develop a custom implementation using the Uniswap Anchored View (UAV) to have a “sanity check” to ensure data from Chainlink Price Feeds were within acceptable bounds of the time-weighted average price of the token/ETH pair on Uniswap v2. To learn more about the UAV’s architecture, please see the Compound Docs.
However, the custom implementation of the UAV is very different from how other protocols integrate Chainlink Price Feeds. These protocols, such as Compound III, use Chainlink Price Feeds directly to retrieve price data. For alternative considerations for this and future proposals, the direct integration method is the preferred route for a streamlined implementation while minimizing the potential for false positives from a reference anchor.
The new UAV3 is deployed in the proposed state with Price Feed aggregator contracts pushing pricing data to it. Currently, the contract is functioning as expected and without issue. If an on-chain vote passes this proposal, the upgrade will immediately take effect to utilize Uniswap V3 prices in the reference anchor.
As with any protocol enhancement, important security implications have been taken into serious consideration to avoid any unintended impact on the Compound II protocol, as the UAV influences its core markets. The original code was audited, and we have worked closely with the OpenZeppelin team to review the small code change and performed tests to ensure a smooth transition to the new UAV. This includes:
- Querying the price directly with the new function to retrieve the correct value without reversion
- Comparing the configuration for cETH with the params file and old versions of the same contract
Linked here, the community can review the result of a successful test that:
- Compares the prices for cTokens with their addresses’ underlying prices
- Compares the proposed UAV and production UAV
You can also run these tests by following the instructions here.
- Proposal Simulations - comprehensive simulation testing before submission for a governance vote.
- Change management - ensuring that code deployed on-chain always matches the versions of the Compound protocol repository to maintain high quality and readability.
As discussed on the developer community call, we want to allow the community to review the updates before going to an on-chain vote this week. We will post an update once the proposal has been submitted on-chain so that the community can prepare to perform post-deployment checks to ensure everything is working correctly.
We look forward to completing the UAV upgrade and invite the Compound community to share their feedback.
Copyright and related rights waived via CC0.
This contribution is offered “as is” without warranty of any kind.