Prisma Optional Oracle Comparative Analysis

Intermediate4/7/2024, 1:34:20 PM
This article evaluates the historical performance of Chainlink integration and the replacement of Curve Pool EMA Oracle. It was found that the lack of reliable Chainlink data sources for collateral assets has impacted integration with the Prisma platform. The study proposes preliminary specifications for improving the Oracle to enhance price accuracy and reliability. Additionally, the research discusses the importance of the Oracle in Prisma liquidation and redemption processes. It is advised to use Curve's price oracle function with caution. Finally, a hybrid solution combining Curve and Chainlink Oracle is proposed to enhance the flexibility and reliability of the pricing mechanism. This report is applicable only to the Prisma protocol.

Introduction

This study originated from the challenge of obtaining reliable on-chain price information that maximizes security while reflecting the current spot prices of target assets. We specifically focus on the collateral assets of Prisma Finance (wstETH, rETH, cbETH, and sfrxETH) as well as Ethereum-based liquid staking derivatives (LSD). Some of these assets lack Chainlink data sources (often considered the gold standard for reliable price data), which has affected their integration with the Prisma platform.

The latest implementation of Curve Finance’s stable pool includes an internal pool Oracle, which calculates the Exponential Moving Average (EMA) to derive tamper-resistant price data. While integrators have begun exploring the use of Oracle in other DeFi applications, the Oracle is primarily used to ensure the safety of collateral in Curve’s own crvUSD market.

The main objective of this report is to determine whether Curve Finance’s Oracle can serve as a reliable alternative to Chainlink for ETH LSD tokens. This study involves statistical analysis of the effectiveness of the Curve price oracle, comparing its volatility, accuracy, and overall performance with Uniswap reference spot prices (assumed to be accurate on-chain prices).

The analysis is divided into two related studies:

stETH Oracles Residual Analysis: A comparison study between Chainlink and Curve, using historical data to determine the Oracle deviation relative to the reference spot price’s mean and standard deviation.

stETH MEV Redemption Analysis: A comparison study between Chainlink and on-chain Oracle, using historical data to examine redemption events on Prisma and estimate robot profitability and expected behavior using alternative Oracles.

After analysis, we provide preliminary specifications for the Oracle, expecting improvements in Oracle price deviation while ensuring Oracle reliability. The proposed solution can serve as an initial blueprint for other studies aiming to optimize the Oracle.

Section 1: Relevant background

1.1 Oracle functions in Prisma protocol

The effectiveness of oracles is assessed within the specific environment of Prisma usage: liquidation and redemption. (Additionally, note that the same oracles are also used for token issuance fees and selling acquired tokens to the “tokenized stable pool,” whose importance will increase once launched.)

The performance of the Oracle is crucial for Prisma users as arbitrageurs may have opportunities to profit from discrepancies between Oracle prices and spot prices. Ensuring the use of the most accurate price feedback during liquidation and redemption, without sacrificing the security of pricing sources, aligns with the best interests of the Prisma protocol and its treasury depositors.

Two Oracle functions within Prisma are outlined as follows:

1.1.1 Liquidation

To protect Prisma from insolvency, where debt positions exceed the value of their collateral, the LiquidationManager contract executes liquidation logic on all active TroveManagers (Prisma treasuries). Liquidation can be triggered in one of three ways, depending on the collateral ratio of the target account and the system-wide collateral ratio.

Individual Collateral Ratio (ICR) <= 100%: The account (treasury) has insufficient collateral. All debt and collateral are redistributed among the remaining active treasuries, effectively socializing the loss.

100% < ICR < Minimum Collateral Ratio (MCR): The treasury falls below the liquidation threshold but can be safely liquidated. The stable pool is used as a reserve for handling liquidations (incentivizing the liquidation pool). Collateral is allocated to stable pool depositors. If the balance of the stable pool is insufficient to fully repay the treasury, the remaining debt and collateral are redistributed among the remaining active treasuries.

MCR <= ICR < Global Total Collateral Ratio (GTCR) && GTCR < 150%: The system is in recovery mode, meaning treasuries can be liquidated when the CR is below GTCR rather than MCR. Stable pool deposits are used first to liquidate the treasury. Collateral equivalent to the debt value at MCR is distributed among stable pool depositors. The remaining collateral can be claimed by the treasury owner.

The possibility of Prisma liquidation increases when ETH or ETH LSD experiences significant price fluctuations, especially declines, in highly volatile market conditions. While Oracle failures or manipulations can affect the protocol at any time, the risk of Oracle failure may increase at the most crucial times. Collateral assets may fail to update prices in a timely manner due to gas fee spikes, or the Oracle’s pricing methodology may not adequately track increased volatility, resulting in mispricing. Insolvencies may increase, requiring redistribution among active treasuries, or borrowers may be unfairly liquidated (in cases where Oracle erroneously reports prices below fair market prices).

1.1.2 Redemption

Arbitrageurs can always initiate redemptions, choosing to redeem 1 mkUSD worth of collateral for 1 US dollar (+ dynamic redemption fees), starting from the treasury with the lowest collateral ratio in the system. This helps strengthen its peg when the mkUSD price falls below 1 US dollar. The redemption process reduces the collateral risk of the target treasury and increases its collateral ratio. The party executing the redemption pays a fee called the redemption fee. The range of redemption fees is per TroveManager and is the sum of the redemption fee floor + the baseRate. Variables stored in TroveManager increase proportionally with the redeemed mkUSD total supply and decrease linearly over time. This dynamic fee, the baseRate, adjusts the profitable redemption rate.

While liquidations on Prisma have historically been rare, redemptions are common and merit special consideration for Oracles. MEV bots actively seek such opportunities to profit quickly through flash loans.

In addition to the inconvenience of forced redemption of their treasuries, users may experience some value extraction due to deviations between the Oracle and spot prices. Mispricing can lead to users losing more assets than necessary, especially when the Oracle reports prices below fair market value. On the other hand, Oracle-reported prices higher than fair market prices may hinder redemptions, negating the purpose of the redemption mechanism enforcing the mkUSD peg floor.

1.2 Oracle options

Here’s a brief look at the leading candidates for Oracle price feeds on Prisma.

1.2.1 Chainlink (off-chain)

Chainlink is a decentralized oracle network that aggregates data from a wide range of market sources and connects this data to smart contracts. Its architecture relies on independent node operators fetching and transmitting data from various exchanges and market data aggregators’ APIs, minimizing single points of failure and enhancing security. Data integrity is ensured through cryptographic methods and consensus mechanisms that verify data accuracy before transmission. Its approach involves volume-weighted asset pricing (VWAP) to aggregate fair market values that best represent asset spot prices.

Node networks regularly (heartbeat) or based on price deviation thresholds push prices onto the chain. This limitation, due to high gas fees on the mainnet, can make price updates expensive and may lead to increased latency, thus reducing Oracle performance. The cost of maintaining such Oracles can be high, especially during periods of high volatility, making timely updates to the Oracle crucial.

1.2.2 Curve pool EMA Oracle (on-chain)

Recent implementations of Curve pools (StableSwap and CryptoSwap pools) include EMA price calculations exposed by getter functions such as price_oracle(). These pools do not rely on external oracles but instead calculate asset prices relative to the token in index 0 of the pool based on their own trading activities internally. The EMA increases manipulation costs through smoothed pricing adjustments, striking a balance between manipulation resistance and price deviation from spot. Each pool has a ma_exp_time that can be configured through Curve DAO voting.

As disclosed in the Curve Oracle documentation, the EMA Oracle has been actively under development:

“If you wish to use Curve’s ‘price oracle’ functionality or any price oracle to provide on-chain pricing data in your decentralized application that you are building, we suggest you exercise extra caution.”

Different pool implementations modify versions of the EMA Oracle code, so integrators must understand the target pool’s Oracle implementation.

In November 2023, an error affecting the pool Oracle was discovered during the deployment implementation of the stableswap-ng pool. This error was found shortly after the pool implementation deployment by yAudit during a secondary audit. This prompted a proposal to upgrade the implementation and deprecate a few affected pools. No funds were at risk, but this event highlighted the active development of Curve pool oracles and the potential for inconsistencies between pools, despite extensive audits, and the potential for errors to continue to exist that could make oracles vulnerable to manipulation or inaccuracies.

1.3 Redemption History MEV

The third part of this report is an analysis of the redemption of wstETH TroveManager. Given the significant impact of redemption on Prisma users, this section presents observations on historical redemptions, which will be evaluated in comparison with the alternative Curve EMA Oracle in the comparative analysis.

1.3.1 BOT behavior

Querying redemption events on the wstETH TroveManager reveals over 200 redemption transactions in total, with 190 transactions identified as BOT transactions (the method used to identify transactions executed by BOTs will be explained later in the same section). Below is a visualization showing the frequency of these transactions over time.

Source: Dune query_3402461

There are only 3 BOTs that frequently exchange mkUSD:

Source: Dune query_3402461

Each BOT follows a similar general process of acquiring mkUSD and redeeming. Below is one of the BOT transactions, revealing some useful insights:

Source: Phalcon Tx Explorer

The BOT transaction pattern can be further subdivided as follows:

Obtain flash loans from Uniswap V3: USDC.

Convert USDC to mkUSD using the Curve.fi Factory USD Metapool: Prisma mkUSD.

Exchange mkUSD for wstETH on the wstETH TroveManager.

Unwrap wstETH into stETH on the wstETH.

Exchange stETH for ETH on the Curve stETH/ETH pool.

Wrap ETH, repay the loan, and distribute profits and commissions.

MEV profitability depends on price differences in steps 2, 3, and 5:

2: As the mkUSD price decreases, redemption profitability increases.

3: As dynamic redemption fees decrease as a function of recent redemption quantities and time since redemption, redemption profitability increases.

-5: As slippage in asset exchanges (e.g., stETH) increases, redemption profitability decreases. LSD such as stETH can be directly exchanged for underlying ETH, but this process requires a waiting period, making liquidity in the secondary market crucial

Prisma employs a mechanism to limit profit opportunities from mkUSD to wstETH redemption through dynamic fees. Step 3 involves dynamic fees to prevent frequent and excessive redemptions. Despite this mechanism, redemptions may still occur due to Oracle mispricing to extract MEV. Oracle quotes for mkUSD redemption may offer treasury owners suboptimal collateral rates, leading to a negative user experience.

1.3.2 Validity of wstETH oracle changes

Prisma Oracle feed pricing change proposal for stETH has been approved. Initially, Prisma used the Chainlink stETH/USD oracle, with a deviation threshold of 1% for the wstETH TroveManager. It was found that using a combination of Chainlink stETH/ETH and ETH/USD oracles could lead to improvement, with a deviation threshold of 0.5% for each oracle.

Please refer to the deviation between the new Oracle and the old Oracle with a 15-block resolution:

Source: Chart by @wavey

It has been observed that when the trading price of mkUSD falls below its pegged rate, excessive redemptions occur due to an Oracle deviation exceeding 1%. In these cases, we found that dynamic fees were insufficient to prevent excessive redemptions caused by pricing deviations. Please refer to the adjustment of redemption fees for redemption events below.

Source: Chart by @wavey

These redemptions may incur indirect costs for Prisma users, as they may receive unfavorable rates when their troves are redeemed. Wavey’s analysis indicates that the stETH/USD oracle is more prone to deviation compared to the oracle combinations validated in the above data. Transient deviations exceeding 1.2% have created opportunities for MEV bots to exploit.

The proposal to change the Oracle (PIP-004) was executed on November 17, 2023, at 7:15:35 PM +UTC, along with this transaction. Based on the mkUSD price chart below and the proposal execution date, it can be observed that after the proposal execution, the realized price of mkUSD in USDC has decreased. The decreased profitability of redemptions due to oracle improvements may result in a decrease in pegging strength.

Source: Dune query_5685458

Other influencing factors should also be considered, including limitations of the protocol interest rate model, use cases for mkUSD, and misaligned incentive measures. Another significant proposal that restricts redemptions is PIP-019, executed on January 31st. This proposal increased the base redemption fee for all TroveManagers to 1%-1.5%, reducing the anchoring elasticity of mkUSD but at the cost of decreasing redemption risk for Prisma trove owners.

Part 2: Oracles Residual Analysis

2.1 Objectives

The analysis aims to assess the performance of the implemented Prisma oracles and evaluate the hypothetical performance of alternative on-chain Curve EMA oracles using historical data. The findings of the study will provide initial insights into the behavior of off-chain and on-chain oracles, enabling a more detailed evaluation in subsequent research.

The purpose of this analysis is to determine whether the current oracle provides the most optimal performance solution or if improvements can be made by implementing on-chain or hybrid solutions utilizing the Curve EMA pool oracle.

2.2 Methodology

The analysis will specifically focus on stETH as it is the most commonly used LSD, with a mature Chainlink price feed and deep liquidity in the Curve pool. Analysis of other collateral listed on Prisma has been conducted, and the results are provided in Appendix B of the report for reference.

The comparative analysis involves assessing the degree of alignment between the trial data and the reference dataset. In this case, two datasets are considered: the trial data of interest and the reference dataset. While it is expected that the trial data should closely track the reference data, deviations may occur.

To quantify alignment, we examine residuals, which essentially represent the difference between the trial data and the reference data. Residual analysis aims to reveal patterns or trends in these differences.

When analyzing residuals (deviations from the reference values), observations are made based on the standard deviation of the residuals. Standard deviation (SD) is a statistical measure used to quantify the variability or dispersion of a set of values. It provides an indication of the distribution of values around the mean (average). A low standard deviation implies that data points tend to be close to the mean, while a high standard deviation indicates that data points are spread out over a wider range.

In our case, a mean close to 0 is desirable as it indicates that the provided prices are not overestimating or underestimating the reference prices. However, a mean close to or equal to 0 with a relatively high standard deviation suggests significant fluctuations, which are undesirable as they correspond to severe mispricing. An oracle feed with a mean of zero and the minimum standard deviation is the ideal outcome, indicating that the feed accurately tracks spot prices.

To monitor and evaluate the accuracy of on-chain oracle price activity, quotes obtained from the most liquid trading destinations (excluding Curve) serve as the reference for residual analysis. Specifically, quotes from the LSD/ETH currency pair on Uniswap are the primary reference points in this scenario.

Our analysis includes two strategies for deriving stETH Chainlink prices. This is done because it was found that the deviation of the original Chainlink stETH/USD feed is higher than the deviation using stETH/ETH + ETH/USD. The oracles were updated according to governance proposals. Subsequently, the analysis involving the improved stETH/ETH Chainlink price in ETH is referred to as stETHv1, while the stETH/USD + ETH/USD combination feed (replicating the original stETH oracle performance, standardized to ETH) is referred to as stETHv2.

2.3 Data collection

For analytical purposes, data for the last quarter of 2023 was obtained from all respective assets (from block 18331000 to block 18931000, with a resolution of 250 blocks for the dataset). This creates a dataset containing 2401 data points for all assets.

The primary asset under consideration is stETH, as it is the collateral type currently accepted by Prisma, with both Chainlink feed and Curve StableSwap-ng pool available for reference (please refer to Appendix B for analysis on rETH and cbETH, which utilizes the older CryptoSwap pool implementation). All data was obtained by querying prices for the specified block range.

Oracle prices are analyzed from the following sources:

Curve liquidity pool

Chainlink Price Feedback

The Uniswap mining pool address as a spot price reference agent is as follows:

Uniswap spot price

To standardize LSD to its underlying ETH, we utilize the internal LSD/ETH exchange rate:

Internal LSD/ETH Exchange Rate

2.4 Residual analysis of stETH oracle machine

2.4.1 Chainlink and Curve

In this section, we will compare the accuracy of the Chainlink stETH price feed with Curve.

Chainlink stETHv1 Feed vs. Curve

Chainlink: stETH/ETH feed

Curve: stETH/ETH pool

Below is a direct comparison of stETH prices from Chainlink and Curve. Due to the 24-hour heartbeat cycle of Chainlink stETH/ETH, the price fluctuates every few blocks. Comparatively, fluctuations are more easily observable in the Chainlink feed (visualized better in the Chainlink stETH/USD feed) compared to Curve, as Curve uses a 10-minute EMA time (ma_exp_time) to derive its price.

If we subtract the price from Curve from the price from Chainlink, we will obtain the residuals, as shown below:

The average deviation value is ~-0.000305.

An important observation that can be made here is that Curve Oracle slightly overestimates its price data compared to Chainlink.

Chainlink stETHv2 and Curve

Chainlink:stETH/USD feed / ETH/USD feed

Curve:stETH/ETH 池

Below is a comparison of prices from alternative Chainlink feeds normalized to ETH (stETH/USD and ETH/USD) versus the stETH Curve. Since Chainlink stETH/USD has a 1% deviation threshold (compared to 0.5% in the stETH/ETH feed), the price exhibits greater deviation around the anchor price.

As previously observed, Chainlink’s stETH/USD price fluctuations are more pronounced compared to Curve.

The average deviation value is ~-0.000171.

Depending on the scale, this feed has larger residuals, i.e. more volatility, than stETH/ETH.

2.4.2 Uniswap and Chainlink

In this section, we will compare the historical accuracy of the Chainlink stETH price feed with the reference spot price from Uniswap.

Assuming UniswapV3 pool price data serves as a reliable proxy for spot prices, we can compare the previously obtained benchmark data to check the proximity of the Chainlink Oracle feed to the reference values.

Uniswap Spot vs. Chainlink stETHv1

Chainlink: stETH/ETH feed

Uniswap: wstETH/ETH pool / wstETH/stETH internal exchange rate

Here is the actual deviation between Uniswap spot price and Chainlink stETH/ETH:

Residual mean = 0.000415

Standard deviation of price differences = 0.000601

Uniswap Spot vs. Chainlink stETHv2

Chainlink: stETH/USD feed / ETH/USD feed

Uniswap: wstETH/ETH pool / wstETH/stETH internal exchange rate

Here is the actual deviation between Uniswap stETH and Chainlink stETH (stETH/USD):

Price difference mean = 0.000281

Price difference standard deviation = 0.002747

Here, we compare Chainlink stETHv1 (i.e., stETH/ETH) and stETHv2 (i.e., stETH/USD) with Uniswap data, and the results indicate that the deviation of stETHv2 is significantly greater than stETHv1.

The same observation was also made in the Prisma governance proposal (PIP-004) when the oracle switched from stETH/USD to stETH/ETH + ETH/USD to reduce price feed deviations.

2.4.3 Uniswap and Curve

In this section, we will compare the historical accuracy of the stETH Curve Oracle with the reference spot price from Uniswap.

Assuming UniswapV3 pool price data serves as a reliable proxy for spot prices, we can compare the previously obtained benchmark data to check the proximity of the Curve Oracle feed to the reference values.

Uniswap Spot vs. Curve

Curve: stETH/ETH pool

Uniswap: wstETH/ETH pool / wstETH/stETH internal exchange rate

Based on a similar residual analysis as above, we get the following metrics to compare with the previously set benchmark:

The mean price difference = 0.000110.

The standard deviation of price differences = 0.000141.

As observed, the average price reported by Curve is slightly lower than the Uniswap spot, with a significantly lower standard deviation compared to either source from Chainlink.

2.5 Results

When comparing these metrics, we find that the deviation of Chainlink data is significantly greater than Curve when referencing Uniswap data as a proxy for spot prices.

Since the above observations are based on the deviations from each price source, it’s possible that the Curve Oracle feed may show positive deviations while Chainlink feed shows negative deviations, and vice versa. This scenario is entirely negated as the deviation ranges of Chainlink feeds and Curve Oracle are smaller compared to the deviation ranges of Uniswap & Chainlink and Uniswap & Curve.

The table below displays residual analysis conducted on the collected data. The residual mean, multiplied by 100, yields the average deviation percentage of the target asset from the reference (in USD terms, compared to USD-denominated ETH prices).

The table directly compares the relative performance of Chainlink and Curve to the Uniswap reference in terms of average and standard deviation for each asset. In all cases, Curve exhibits lower average and standard deviation values. The accuracy multiplier shows the relative accuracy of each observed value.

The main points here are as follows:

  1. Based on the standard deviation of residuals, Curve displays lower volatility compared to Chainlink relative to the reference spot prices, and this holds consistent across the observed assets, although the standard deviation between cbETH for Chainlink and Curve is similar.
  2. According to the table above, through analyzing the means, it can be observed that Chainlink underestimates asset prices compared to the reference Uniswap spot prices. Curve aligns more closely with the reference prices, but also tends to slightly underestimate prices compared to the reference Uniswap spot prices.
  3. A caveat to these findings is that despite the overall superiority of Curve Oracle over Chainlink observed here, rETH and cbETH experienced sharp and short-lived deviations, as referenced in Appendix B: rETH/cbETH Residual Analysis. This is attributed to relative illiquidity of the pools, low activity, and the inadequacy of the older pool implementations for integration. However, further research is needed to determine the benchmark metrics required for appropriately reliable Curve pool Oracles.

Section 3: stETH MEV Redemption Analysis

3.1 Objectives

The analysis aims to compare the implementation prices of redemption events in the wstETH TroveManager with the hypothetical prices quoted using historical data by alternative on-chain oracles. The results of the study will provide initial insights into the behavior of off-chain and on-chain oracles, enabling a more detailed evaluation in subsequent research.

The purpose of this analysis is to determine whether the current oracle provides the best performance solution in specific redemption scenarios or if improvements can be made through the implementation of on-chain or hybrid solutions, utilizing Curve EMA pool oracles.

3.2 Methodology

This analysis will specifically focus on stETH, as it is the most commonly used LSD and has mature Chainlink price feeds and deep liquidity in the Curve pool. The study will aggregate all redemption events, comparing the realized stETH oracle prices with several alternative oracle prices, priced in USD, and using the Curve stETH/ETH oracle price.

For this analysis, the realized stETH price is calculated by dividing the redeemed amount of mkUSD by the amount of stETH lost to the Trove Manager in the form of wstETH. To determine the amount of stETH, we need to consider the received wstETH from the redemption plus the wstETH spent as fees and convert them to stETH. If any alternative source consistently offers lower profits to redeemers, we can say that their MEV performance is better than the actual price.

The wstETH TroveManager is used to retrieve all transaction hashes when obtaining mkUSD in exchange. Transactions where the address redeeming mkUSD receives and burns mkUSD are considered BOT transactions. Detailed queries for redemption events can be found here: Dune query_3352919. This query is essential for retrieving all data from BOT transactions.

3.3 Data collection

Dune query is used to identify BOT transactions that obtain all transaction hash values, the realized wstETH exchange rate for mkUSD redemption, and the block number of redemption events. The block numbers obtained from the query are used as inputs to query the following data, which is used to compare the current implementation with changes in the Curve stETH feed price:

Based on the above data, we can construct three price feeds using the Curve Oracle stETH/ETH price, and merge them with ETH/USD to derive stETH/USD. After this operation, we obtain the following data for visualization:

The above data provides the stETH price in USD, which can be analyzed based on the realized stETH prices from all BOT transactions. The realized stETH (in USD) is simply used to calculate the stETH price for each mkUSD provided during redemption.

3.4 stETH MEV Redemption Analysis

Below are 4 stETH price sources for the BOT trading block (1 reference and 3 alternatives discussed above). Realized price feeds are prices from implemented price oracles (i.e. Chainlink). This is compared to 3 feeds using Curve stETH/ETH as the core. Here, a higher quote will result in a decrease in the value of stETH exchanged for mkUSD and vice versa.

Based on the above information, we can model the relative amount of stETH received from redeeming mkUSD and normalize it based on the actual amount received from the existing oracle. The following graph displays the stETH obtained from mkUSD before fees are charged and processes the data to remove outliers for improved visualization:

3.5 Results

The analysis reveals a clear trend: when combining Curve stETH/ETH with Uniswap ETH/USDC and Chainlink ETH/USD, the amount of stETH available for mkUSD redemption decreases. Consequently, a reduction in the number of stETH units per mkUSD redemption leads to a decrease in BOT profits. The provided visualization illustrates the comparison between BOT profits under various assumed feed prices and the actual feed price, excluding fees:

It is evident that the combination of Curve stETH/ETH, Uniswap ETH/USDC, and Chainlink ETH/USD reduces the profitability of redemptions compared to the realized feed price.

Part 4: Proposed Oracle Improvements

4.1 Hybrid Oracle solution

Recognizing the inherent risks of relying solely on the Curve oracle, particularly during periods of low liquidity or liquidity fluctuations, the proposed solution strategically integrates the Chainlink oracle as a safeguard measure (i.e., a backup plan) in case of deviations. Considering the negligible possibility of Chainlink providing incorrect data, it can serve as a reliable backup option.

This solution acts as a filter, considering both Curve and Chainlink prices. Conditions are established within a function, serving as a switch. To design this condition, the concept of an acceptable range is introduced. This range represents the acceptable difference between Chainlink and Curve oracle prices. When the observed difference exceeds this range, it indicates potential bias or manipulation in the Curve Oracle data. In such cases, the function mitigates potential risks by favoring the more secure Chainlink prices. Conversely, when the difference falls within the acceptable range, the function relies on the accuracy and precision of the Curve Oracle.

It is worth noting that the acceptable range can be configured as static or dynamic, depending on the volatility of the underlying assets (e.g., ETH and related LSD). The dynamic nature allows adaptation to volatile market conditions, ensuring elasticity and response mechanisms in price determination. This dual-pronged strategy minimizes reliance on a single data source, thereby enhancing the overall resilience and reliability of the pricing mechanism.

4.2 Verification solution

4.2.1 Static acceptable_range

The solution introduces a static method, acceptable_range, to address potential vulnerabilities when relying solely on the Curve Oracle. While the prices generated by the Curve Oracle may be more accurate than Chainlink, it could be susceptible to manipulation. Chainlink, on the other hand, is robust and tested, considered a safer choice in the industry. When the difference between Curve Oracle and Chainlink exceeds a fixed value, the acceptable_range serves as a threshold to switch to the Chainlink feed.

Strategically, the acceptable_range accepts quotes that are within ±1% of the Chainlink quotes. This is nearly three standard deviations away from the average difference between Curve and Chainlink, considering the improved stETH/ETH and ETH/USD feeds compared to the previous stETH/USD feed.

4.2.2 Function output derived_price

The derived_price is a function or mechanism designed to determine the final quote for a given asset, especially in scenarios involving the Curve Oracle and Chainlink Oracle.

In the described solution, this function evaluates quotes from both the Curve Oracle and Chainlink Oracle. Based on the observed difference between these two prices and whether it falls within or exceeds the predefined accepted_range, the function outputs different derived prices.

Here is a comparison of derived_price with the other price sources previously displayed:

BOT profits can be visualized by this derivative price (since there is no deviation, this price will be exactly equal to Curve stETH/ETH and CL stETH/ETH) as shown below:

Analyzing total profits can reveal the bigger picture. Six outliers were identified and the total profit for each case was calculated before and after filtering the outliers.

Curve stETH/ETH and Uniswap ETH/USDC perform the best in reducing the available profit for BOTs. The derived_price they provide has the same profit potential as the current stETH Oracle implementation but limits the profit, assuming it saves users approximately 35.4 ETH across the analyzed 189 transactions.

4.3 Conclusion

Due to the heavy reliance on quotes from the most liquid decentralized exchanges for on-chain activities and the fact that MEV bots also follow the same quotes when exchanging mkUSD for LSD, the accuracy of quotes (used for pricing redemptions by the Oracle) is of paramount importance.

Historical data suggests that the Curve pool Oracle prices are closer to the reference (UniswapV3 price data) compared to Chainlink prices. The data indicates that implementing Curve Oracle would reduce MEV for bots and provide better exchange rates for users redeeming their treasures.

While using Curve Oracle as a standalone Oracle might be tempting, the effectiveness of Curve price feedback depends on the liquidity depth of specific assets and interaction with the pool. A hybrid Oracle solution with Curve Oracle and Chainlink Oracle can be used to match on-chain prices while retaining the reliability and broad market coverage inherited from Chainlink Oracle.

The hybrid Oracle solution we propose evaluates the standard deviation (SD) to generate derived_price. If the SD approaches 0, it indicates adherence to the derived_price reference values, making it worth considering. This ensures that when Curve Oracle deviates from predefined thresholds, the solution dynamically switches to the safer Chainlink source. As this solution almost always outputs stETH’s Curve quote, it is assumed that MEV activity is the same as using Curve stETH/ETH, with no fallback.

Appendix A: Data Processing Scripts

The scripts used to generate the analysis in this report are as follows:

  1. OracleAnalysisV4: Colab notebook for data collection
  2. OracleAnalysisPlayground: Colab notebook for plotting charts using pickle data files
  3. PrismaOracleModelingV1: Colab notebook for plotting MEV exchange activity charts
  4. DerivedPriceModeling: Colab notebook for testing and modeling alternative Oracle solutions

Appendix B: rETH/cbETH residual analysis

Other Charts rETH

Chainlink and Curve

Uniswap and Curve

Uniswap and Chainlink

Check peak rETH

在观察期间,rETH 曲线预言机价格出现了几次峰值。这导致预言机价格和现货参考之间的价格偏差激增。下面是更详细的图表,显示了几次价格飙升期间的资金池比例/代币流动性以及预言机价格的行为。

start_block = 18824000

end_block = 18827000

interval_blocks = 100

Mining pool ratio:

Oracle price:

start_block = 18850000

end_block = 18858000

interval_blocks = 100

Mining pool ratio:

Oracle price:

start_block = 18880000

end_block = 18885000

interval_blocks = 100

Mining pool ratio:

Oracle price:

Other Charts cbETH

Chainlink and Curve

Uniswap and Curve

Uniswap and Chainlink

Check Peak cbETH

During the observation period, the cbETH Curve Oracle prices experienced several peaks. On several occasions, this resulted in significant spikes in the price deviation between the Oracle price and the spot reference. Below is a more detailed chart showing the behavior of the liquidity pool ratios/token liquidity during these periods of price surges and the behavior of the Oracle prices.

start_block = 18693500

end_block = 18696000

interval_blocks = 10

Mining pool ratio:

Oracle price:

start_block = 18814000

end_block = 18816500

interval_blocks = 10

Mining pool ratio:

Oracle price:

start_block = 18800000

end_block = 18805000

interval_blocks = 10

Mining pool ratio:

Oracle price:

Statement:

  1. This article is reproduced from [marsbit], original title “Comparative analysis of Prisma optional oracles”, the copyright belongs to the original author [PrismaRisk], if you have any objection to the reprint, please contact Gate Learn Team, the team will handle it as soon as possible according to relevant procedures.

  2. Disclaimer: The views and opinions expressed in this article represent only the author’s personal views and do not constitute any investment advice.

  3. Other language versions of the article are translated by the Gate Learn team, not mentioned in Gate.io, the translated article may not be reproduced, distributed or plagiarized.

Prisma Optional Oracle Comparative Analysis

Intermediate4/7/2024, 1:34:20 PM
This article evaluates the historical performance of Chainlink integration and the replacement of Curve Pool EMA Oracle. It was found that the lack of reliable Chainlink data sources for collateral assets has impacted integration with the Prisma platform. The study proposes preliminary specifications for improving the Oracle to enhance price accuracy and reliability. Additionally, the research discusses the importance of the Oracle in Prisma liquidation and redemption processes. It is advised to use Curve's price oracle function with caution. Finally, a hybrid solution combining Curve and Chainlink Oracle is proposed to enhance the flexibility and reliability of the pricing mechanism. This report is applicable only to the Prisma protocol.

Introduction

This study originated from the challenge of obtaining reliable on-chain price information that maximizes security while reflecting the current spot prices of target assets. We specifically focus on the collateral assets of Prisma Finance (wstETH, rETH, cbETH, and sfrxETH) as well as Ethereum-based liquid staking derivatives (LSD). Some of these assets lack Chainlink data sources (often considered the gold standard for reliable price data), which has affected their integration with the Prisma platform.

The latest implementation of Curve Finance’s stable pool includes an internal pool Oracle, which calculates the Exponential Moving Average (EMA) to derive tamper-resistant price data. While integrators have begun exploring the use of Oracle in other DeFi applications, the Oracle is primarily used to ensure the safety of collateral in Curve’s own crvUSD market.

The main objective of this report is to determine whether Curve Finance’s Oracle can serve as a reliable alternative to Chainlink for ETH LSD tokens. This study involves statistical analysis of the effectiveness of the Curve price oracle, comparing its volatility, accuracy, and overall performance with Uniswap reference spot prices (assumed to be accurate on-chain prices).

The analysis is divided into two related studies:

stETH Oracles Residual Analysis: A comparison study between Chainlink and Curve, using historical data to determine the Oracle deviation relative to the reference spot price’s mean and standard deviation.

stETH MEV Redemption Analysis: A comparison study between Chainlink and on-chain Oracle, using historical data to examine redemption events on Prisma and estimate robot profitability and expected behavior using alternative Oracles.

After analysis, we provide preliminary specifications for the Oracle, expecting improvements in Oracle price deviation while ensuring Oracle reliability. The proposed solution can serve as an initial blueprint for other studies aiming to optimize the Oracle.

Section 1: Relevant background

1.1 Oracle functions in Prisma protocol

The effectiveness of oracles is assessed within the specific environment of Prisma usage: liquidation and redemption. (Additionally, note that the same oracles are also used for token issuance fees and selling acquired tokens to the “tokenized stable pool,” whose importance will increase once launched.)

The performance of the Oracle is crucial for Prisma users as arbitrageurs may have opportunities to profit from discrepancies between Oracle prices and spot prices. Ensuring the use of the most accurate price feedback during liquidation and redemption, without sacrificing the security of pricing sources, aligns with the best interests of the Prisma protocol and its treasury depositors.

Two Oracle functions within Prisma are outlined as follows:

1.1.1 Liquidation

To protect Prisma from insolvency, where debt positions exceed the value of their collateral, the LiquidationManager contract executes liquidation logic on all active TroveManagers (Prisma treasuries). Liquidation can be triggered in one of three ways, depending on the collateral ratio of the target account and the system-wide collateral ratio.

Individual Collateral Ratio (ICR) <= 100%: The account (treasury) has insufficient collateral. All debt and collateral are redistributed among the remaining active treasuries, effectively socializing the loss.

100% < ICR < Minimum Collateral Ratio (MCR): The treasury falls below the liquidation threshold but can be safely liquidated. The stable pool is used as a reserve for handling liquidations (incentivizing the liquidation pool). Collateral is allocated to stable pool depositors. If the balance of the stable pool is insufficient to fully repay the treasury, the remaining debt and collateral are redistributed among the remaining active treasuries.

MCR <= ICR < Global Total Collateral Ratio (GTCR) && GTCR < 150%: The system is in recovery mode, meaning treasuries can be liquidated when the CR is below GTCR rather than MCR. Stable pool deposits are used first to liquidate the treasury. Collateral equivalent to the debt value at MCR is distributed among stable pool depositors. The remaining collateral can be claimed by the treasury owner.

The possibility of Prisma liquidation increases when ETH or ETH LSD experiences significant price fluctuations, especially declines, in highly volatile market conditions. While Oracle failures or manipulations can affect the protocol at any time, the risk of Oracle failure may increase at the most crucial times. Collateral assets may fail to update prices in a timely manner due to gas fee spikes, or the Oracle’s pricing methodology may not adequately track increased volatility, resulting in mispricing. Insolvencies may increase, requiring redistribution among active treasuries, or borrowers may be unfairly liquidated (in cases where Oracle erroneously reports prices below fair market prices).

1.1.2 Redemption

Arbitrageurs can always initiate redemptions, choosing to redeem 1 mkUSD worth of collateral for 1 US dollar (+ dynamic redemption fees), starting from the treasury with the lowest collateral ratio in the system. This helps strengthen its peg when the mkUSD price falls below 1 US dollar. The redemption process reduces the collateral risk of the target treasury and increases its collateral ratio. The party executing the redemption pays a fee called the redemption fee. The range of redemption fees is per TroveManager and is the sum of the redemption fee floor + the baseRate. Variables stored in TroveManager increase proportionally with the redeemed mkUSD total supply and decrease linearly over time. This dynamic fee, the baseRate, adjusts the profitable redemption rate.

While liquidations on Prisma have historically been rare, redemptions are common and merit special consideration for Oracles. MEV bots actively seek such opportunities to profit quickly through flash loans.

In addition to the inconvenience of forced redemption of their treasuries, users may experience some value extraction due to deviations between the Oracle and spot prices. Mispricing can lead to users losing more assets than necessary, especially when the Oracle reports prices below fair market value. On the other hand, Oracle-reported prices higher than fair market prices may hinder redemptions, negating the purpose of the redemption mechanism enforcing the mkUSD peg floor.

1.2 Oracle options

Here’s a brief look at the leading candidates for Oracle price feeds on Prisma.

1.2.1 Chainlink (off-chain)

Chainlink is a decentralized oracle network that aggregates data from a wide range of market sources and connects this data to smart contracts. Its architecture relies on independent node operators fetching and transmitting data from various exchanges and market data aggregators’ APIs, minimizing single points of failure and enhancing security. Data integrity is ensured through cryptographic methods and consensus mechanisms that verify data accuracy before transmission. Its approach involves volume-weighted asset pricing (VWAP) to aggregate fair market values that best represent asset spot prices.

Node networks regularly (heartbeat) or based on price deviation thresholds push prices onto the chain. This limitation, due to high gas fees on the mainnet, can make price updates expensive and may lead to increased latency, thus reducing Oracle performance. The cost of maintaining such Oracles can be high, especially during periods of high volatility, making timely updates to the Oracle crucial.

1.2.2 Curve pool EMA Oracle (on-chain)

Recent implementations of Curve pools (StableSwap and CryptoSwap pools) include EMA price calculations exposed by getter functions such as price_oracle(). These pools do not rely on external oracles but instead calculate asset prices relative to the token in index 0 of the pool based on their own trading activities internally. The EMA increases manipulation costs through smoothed pricing adjustments, striking a balance between manipulation resistance and price deviation from spot. Each pool has a ma_exp_time that can be configured through Curve DAO voting.

As disclosed in the Curve Oracle documentation, the EMA Oracle has been actively under development:

“If you wish to use Curve’s ‘price oracle’ functionality or any price oracle to provide on-chain pricing data in your decentralized application that you are building, we suggest you exercise extra caution.”

Different pool implementations modify versions of the EMA Oracle code, so integrators must understand the target pool’s Oracle implementation.

In November 2023, an error affecting the pool Oracle was discovered during the deployment implementation of the stableswap-ng pool. This error was found shortly after the pool implementation deployment by yAudit during a secondary audit. This prompted a proposal to upgrade the implementation and deprecate a few affected pools. No funds were at risk, but this event highlighted the active development of Curve pool oracles and the potential for inconsistencies between pools, despite extensive audits, and the potential for errors to continue to exist that could make oracles vulnerable to manipulation or inaccuracies.

1.3 Redemption History MEV

The third part of this report is an analysis of the redemption of wstETH TroveManager. Given the significant impact of redemption on Prisma users, this section presents observations on historical redemptions, which will be evaluated in comparison with the alternative Curve EMA Oracle in the comparative analysis.

1.3.1 BOT behavior

Querying redemption events on the wstETH TroveManager reveals over 200 redemption transactions in total, with 190 transactions identified as BOT transactions (the method used to identify transactions executed by BOTs will be explained later in the same section). Below is a visualization showing the frequency of these transactions over time.

Source: Dune query_3402461

There are only 3 BOTs that frequently exchange mkUSD:

Source: Dune query_3402461

Each BOT follows a similar general process of acquiring mkUSD and redeeming. Below is one of the BOT transactions, revealing some useful insights:

Source: Phalcon Tx Explorer

The BOT transaction pattern can be further subdivided as follows:

Obtain flash loans from Uniswap V3: USDC.

Convert USDC to mkUSD using the Curve.fi Factory USD Metapool: Prisma mkUSD.

Exchange mkUSD for wstETH on the wstETH TroveManager.

Unwrap wstETH into stETH on the wstETH.

Exchange stETH for ETH on the Curve stETH/ETH pool.

Wrap ETH, repay the loan, and distribute profits and commissions.

MEV profitability depends on price differences in steps 2, 3, and 5:

2: As the mkUSD price decreases, redemption profitability increases.

3: As dynamic redemption fees decrease as a function of recent redemption quantities and time since redemption, redemption profitability increases.

-5: As slippage in asset exchanges (e.g., stETH) increases, redemption profitability decreases. LSD such as stETH can be directly exchanged for underlying ETH, but this process requires a waiting period, making liquidity in the secondary market crucial

Prisma employs a mechanism to limit profit opportunities from mkUSD to wstETH redemption through dynamic fees. Step 3 involves dynamic fees to prevent frequent and excessive redemptions. Despite this mechanism, redemptions may still occur due to Oracle mispricing to extract MEV. Oracle quotes for mkUSD redemption may offer treasury owners suboptimal collateral rates, leading to a negative user experience.

1.3.2 Validity of wstETH oracle changes

Prisma Oracle feed pricing change proposal for stETH has been approved. Initially, Prisma used the Chainlink stETH/USD oracle, with a deviation threshold of 1% for the wstETH TroveManager. It was found that using a combination of Chainlink stETH/ETH and ETH/USD oracles could lead to improvement, with a deviation threshold of 0.5% for each oracle.

Please refer to the deviation between the new Oracle and the old Oracle with a 15-block resolution:

Source: Chart by @wavey

It has been observed that when the trading price of mkUSD falls below its pegged rate, excessive redemptions occur due to an Oracle deviation exceeding 1%. In these cases, we found that dynamic fees were insufficient to prevent excessive redemptions caused by pricing deviations. Please refer to the adjustment of redemption fees for redemption events below.

Source: Chart by @wavey

These redemptions may incur indirect costs for Prisma users, as they may receive unfavorable rates when their troves are redeemed. Wavey’s analysis indicates that the stETH/USD oracle is more prone to deviation compared to the oracle combinations validated in the above data. Transient deviations exceeding 1.2% have created opportunities for MEV bots to exploit.

The proposal to change the Oracle (PIP-004) was executed on November 17, 2023, at 7:15:35 PM +UTC, along with this transaction. Based on the mkUSD price chart below and the proposal execution date, it can be observed that after the proposal execution, the realized price of mkUSD in USDC has decreased. The decreased profitability of redemptions due to oracle improvements may result in a decrease in pegging strength.

Source: Dune query_5685458

Other influencing factors should also be considered, including limitations of the protocol interest rate model, use cases for mkUSD, and misaligned incentive measures. Another significant proposal that restricts redemptions is PIP-019, executed on January 31st. This proposal increased the base redemption fee for all TroveManagers to 1%-1.5%, reducing the anchoring elasticity of mkUSD but at the cost of decreasing redemption risk for Prisma trove owners.

Part 2: Oracles Residual Analysis

2.1 Objectives

The analysis aims to assess the performance of the implemented Prisma oracles and evaluate the hypothetical performance of alternative on-chain Curve EMA oracles using historical data. The findings of the study will provide initial insights into the behavior of off-chain and on-chain oracles, enabling a more detailed evaluation in subsequent research.

The purpose of this analysis is to determine whether the current oracle provides the most optimal performance solution or if improvements can be made by implementing on-chain or hybrid solutions utilizing the Curve EMA pool oracle.

2.2 Methodology

The analysis will specifically focus on stETH as it is the most commonly used LSD, with a mature Chainlink price feed and deep liquidity in the Curve pool. Analysis of other collateral listed on Prisma has been conducted, and the results are provided in Appendix B of the report for reference.

The comparative analysis involves assessing the degree of alignment between the trial data and the reference dataset. In this case, two datasets are considered: the trial data of interest and the reference dataset. While it is expected that the trial data should closely track the reference data, deviations may occur.

To quantify alignment, we examine residuals, which essentially represent the difference between the trial data and the reference data. Residual analysis aims to reveal patterns or trends in these differences.

When analyzing residuals (deviations from the reference values), observations are made based on the standard deviation of the residuals. Standard deviation (SD) is a statistical measure used to quantify the variability or dispersion of a set of values. It provides an indication of the distribution of values around the mean (average). A low standard deviation implies that data points tend to be close to the mean, while a high standard deviation indicates that data points are spread out over a wider range.

In our case, a mean close to 0 is desirable as it indicates that the provided prices are not overestimating or underestimating the reference prices. However, a mean close to or equal to 0 with a relatively high standard deviation suggests significant fluctuations, which are undesirable as they correspond to severe mispricing. An oracle feed with a mean of zero and the minimum standard deviation is the ideal outcome, indicating that the feed accurately tracks spot prices.

To monitor and evaluate the accuracy of on-chain oracle price activity, quotes obtained from the most liquid trading destinations (excluding Curve) serve as the reference for residual analysis. Specifically, quotes from the LSD/ETH currency pair on Uniswap are the primary reference points in this scenario.

Our analysis includes two strategies for deriving stETH Chainlink prices. This is done because it was found that the deviation of the original Chainlink stETH/USD feed is higher than the deviation using stETH/ETH + ETH/USD. The oracles were updated according to governance proposals. Subsequently, the analysis involving the improved stETH/ETH Chainlink price in ETH is referred to as stETHv1, while the stETH/USD + ETH/USD combination feed (replicating the original stETH oracle performance, standardized to ETH) is referred to as stETHv2.

2.3 Data collection

For analytical purposes, data for the last quarter of 2023 was obtained from all respective assets (from block 18331000 to block 18931000, with a resolution of 250 blocks for the dataset). This creates a dataset containing 2401 data points for all assets.

The primary asset under consideration is stETH, as it is the collateral type currently accepted by Prisma, with both Chainlink feed and Curve StableSwap-ng pool available for reference (please refer to Appendix B for analysis on rETH and cbETH, which utilizes the older CryptoSwap pool implementation). All data was obtained by querying prices for the specified block range.

Oracle prices are analyzed from the following sources:

Curve liquidity pool

Chainlink Price Feedback

The Uniswap mining pool address as a spot price reference agent is as follows:

Uniswap spot price

To standardize LSD to its underlying ETH, we utilize the internal LSD/ETH exchange rate:

Internal LSD/ETH Exchange Rate

2.4 Residual analysis of stETH oracle machine

2.4.1 Chainlink and Curve

In this section, we will compare the accuracy of the Chainlink stETH price feed with Curve.

Chainlink stETHv1 Feed vs. Curve

Chainlink: stETH/ETH feed

Curve: stETH/ETH pool

Below is a direct comparison of stETH prices from Chainlink and Curve. Due to the 24-hour heartbeat cycle of Chainlink stETH/ETH, the price fluctuates every few blocks. Comparatively, fluctuations are more easily observable in the Chainlink feed (visualized better in the Chainlink stETH/USD feed) compared to Curve, as Curve uses a 10-minute EMA time (ma_exp_time) to derive its price.

If we subtract the price from Curve from the price from Chainlink, we will obtain the residuals, as shown below:

The average deviation value is ~-0.000305.

An important observation that can be made here is that Curve Oracle slightly overestimates its price data compared to Chainlink.

Chainlink stETHv2 and Curve

Chainlink:stETH/USD feed / ETH/USD feed

Curve:stETH/ETH 池

Below is a comparison of prices from alternative Chainlink feeds normalized to ETH (stETH/USD and ETH/USD) versus the stETH Curve. Since Chainlink stETH/USD has a 1% deviation threshold (compared to 0.5% in the stETH/ETH feed), the price exhibits greater deviation around the anchor price.

As previously observed, Chainlink’s stETH/USD price fluctuations are more pronounced compared to Curve.

The average deviation value is ~-0.000171.

Depending on the scale, this feed has larger residuals, i.e. more volatility, than stETH/ETH.

2.4.2 Uniswap and Chainlink

In this section, we will compare the historical accuracy of the Chainlink stETH price feed with the reference spot price from Uniswap.

Assuming UniswapV3 pool price data serves as a reliable proxy for spot prices, we can compare the previously obtained benchmark data to check the proximity of the Chainlink Oracle feed to the reference values.

Uniswap Spot vs. Chainlink stETHv1

Chainlink: stETH/ETH feed

Uniswap: wstETH/ETH pool / wstETH/stETH internal exchange rate

Here is the actual deviation between Uniswap spot price and Chainlink stETH/ETH:

Residual mean = 0.000415

Standard deviation of price differences = 0.000601

Uniswap Spot vs. Chainlink stETHv2

Chainlink: stETH/USD feed / ETH/USD feed

Uniswap: wstETH/ETH pool / wstETH/stETH internal exchange rate

Here is the actual deviation between Uniswap stETH and Chainlink stETH (stETH/USD):

Price difference mean = 0.000281

Price difference standard deviation = 0.002747

Here, we compare Chainlink stETHv1 (i.e., stETH/ETH) and stETHv2 (i.e., stETH/USD) with Uniswap data, and the results indicate that the deviation of stETHv2 is significantly greater than stETHv1.

The same observation was also made in the Prisma governance proposal (PIP-004) when the oracle switched from stETH/USD to stETH/ETH + ETH/USD to reduce price feed deviations.

2.4.3 Uniswap and Curve

In this section, we will compare the historical accuracy of the stETH Curve Oracle with the reference spot price from Uniswap.

Assuming UniswapV3 pool price data serves as a reliable proxy for spot prices, we can compare the previously obtained benchmark data to check the proximity of the Curve Oracle feed to the reference values.

Uniswap Spot vs. Curve

Curve: stETH/ETH pool

Uniswap: wstETH/ETH pool / wstETH/stETH internal exchange rate

Based on a similar residual analysis as above, we get the following metrics to compare with the previously set benchmark:

The mean price difference = 0.000110.

The standard deviation of price differences = 0.000141.

As observed, the average price reported by Curve is slightly lower than the Uniswap spot, with a significantly lower standard deviation compared to either source from Chainlink.

2.5 Results

When comparing these metrics, we find that the deviation of Chainlink data is significantly greater than Curve when referencing Uniswap data as a proxy for spot prices.

Since the above observations are based on the deviations from each price source, it’s possible that the Curve Oracle feed may show positive deviations while Chainlink feed shows negative deviations, and vice versa. This scenario is entirely negated as the deviation ranges of Chainlink feeds and Curve Oracle are smaller compared to the deviation ranges of Uniswap & Chainlink and Uniswap & Curve.

The table below displays residual analysis conducted on the collected data. The residual mean, multiplied by 100, yields the average deviation percentage of the target asset from the reference (in USD terms, compared to USD-denominated ETH prices).

The table directly compares the relative performance of Chainlink and Curve to the Uniswap reference in terms of average and standard deviation for each asset. In all cases, Curve exhibits lower average and standard deviation values. The accuracy multiplier shows the relative accuracy of each observed value.

The main points here are as follows:

  1. Based on the standard deviation of residuals, Curve displays lower volatility compared to Chainlink relative to the reference spot prices, and this holds consistent across the observed assets, although the standard deviation between cbETH for Chainlink and Curve is similar.
  2. According to the table above, through analyzing the means, it can be observed that Chainlink underestimates asset prices compared to the reference Uniswap spot prices. Curve aligns more closely with the reference prices, but also tends to slightly underestimate prices compared to the reference Uniswap spot prices.
  3. A caveat to these findings is that despite the overall superiority of Curve Oracle over Chainlink observed here, rETH and cbETH experienced sharp and short-lived deviations, as referenced in Appendix B: rETH/cbETH Residual Analysis. This is attributed to relative illiquidity of the pools, low activity, and the inadequacy of the older pool implementations for integration. However, further research is needed to determine the benchmark metrics required for appropriately reliable Curve pool Oracles.

Section 3: stETH MEV Redemption Analysis

3.1 Objectives

The analysis aims to compare the implementation prices of redemption events in the wstETH TroveManager with the hypothetical prices quoted using historical data by alternative on-chain oracles. The results of the study will provide initial insights into the behavior of off-chain and on-chain oracles, enabling a more detailed evaluation in subsequent research.

The purpose of this analysis is to determine whether the current oracle provides the best performance solution in specific redemption scenarios or if improvements can be made through the implementation of on-chain or hybrid solutions, utilizing Curve EMA pool oracles.

3.2 Methodology

This analysis will specifically focus on stETH, as it is the most commonly used LSD and has mature Chainlink price feeds and deep liquidity in the Curve pool. The study will aggregate all redemption events, comparing the realized stETH oracle prices with several alternative oracle prices, priced in USD, and using the Curve stETH/ETH oracle price.

For this analysis, the realized stETH price is calculated by dividing the redeemed amount of mkUSD by the amount of stETH lost to the Trove Manager in the form of wstETH. To determine the amount of stETH, we need to consider the received wstETH from the redemption plus the wstETH spent as fees and convert them to stETH. If any alternative source consistently offers lower profits to redeemers, we can say that their MEV performance is better than the actual price.

The wstETH TroveManager is used to retrieve all transaction hashes when obtaining mkUSD in exchange. Transactions where the address redeeming mkUSD receives and burns mkUSD are considered BOT transactions. Detailed queries for redemption events can be found here: Dune query_3352919. This query is essential for retrieving all data from BOT transactions.

3.3 Data collection

Dune query is used to identify BOT transactions that obtain all transaction hash values, the realized wstETH exchange rate for mkUSD redemption, and the block number of redemption events. The block numbers obtained from the query are used as inputs to query the following data, which is used to compare the current implementation with changes in the Curve stETH feed price:

Based on the above data, we can construct three price feeds using the Curve Oracle stETH/ETH price, and merge them with ETH/USD to derive stETH/USD. After this operation, we obtain the following data for visualization:

The above data provides the stETH price in USD, which can be analyzed based on the realized stETH prices from all BOT transactions. The realized stETH (in USD) is simply used to calculate the stETH price for each mkUSD provided during redemption.

3.4 stETH MEV Redemption Analysis

Below are 4 stETH price sources for the BOT trading block (1 reference and 3 alternatives discussed above). Realized price feeds are prices from implemented price oracles (i.e. Chainlink). This is compared to 3 feeds using Curve stETH/ETH as the core. Here, a higher quote will result in a decrease in the value of stETH exchanged for mkUSD and vice versa.

Based on the above information, we can model the relative amount of stETH received from redeeming mkUSD and normalize it based on the actual amount received from the existing oracle. The following graph displays the stETH obtained from mkUSD before fees are charged and processes the data to remove outliers for improved visualization:

3.5 Results

The analysis reveals a clear trend: when combining Curve stETH/ETH with Uniswap ETH/USDC and Chainlink ETH/USD, the amount of stETH available for mkUSD redemption decreases. Consequently, a reduction in the number of stETH units per mkUSD redemption leads to a decrease in BOT profits. The provided visualization illustrates the comparison between BOT profits under various assumed feed prices and the actual feed price, excluding fees:

It is evident that the combination of Curve stETH/ETH, Uniswap ETH/USDC, and Chainlink ETH/USD reduces the profitability of redemptions compared to the realized feed price.

Part 4: Proposed Oracle Improvements

4.1 Hybrid Oracle solution

Recognizing the inherent risks of relying solely on the Curve oracle, particularly during periods of low liquidity or liquidity fluctuations, the proposed solution strategically integrates the Chainlink oracle as a safeguard measure (i.e., a backup plan) in case of deviations. Considering the negligible possibility of Chainlink providing incorrect data, it can serve as a reliable backup option.

This solution acts as a filter, considering both Curve and Chainlink prices. Conditions are established within a function, serving as a switch. To design this condition, the concept of an acceptable range is introduced. This range represents the acceptable difference between Chainlink and Curve oracle prices. When the observed difference exceeds this range, it indicates potential bias or manipulation in the Curve Oracle data. In such cases, the function mitigates potential risks by favoring the more secure Chainlink prices. Conversely, when the difference falls within the acceptable range, the function relies on the accuracy and precision of the Curve Oracle.

It is worth noting that the acceptable range can be configured as static or dynamic, depending on the volatility of the underlying assets (e.g., ETH and related LSD). The dynamic nature allows adaptation to volatile market conditions, ensuring elasticity and response mechanisms in price determination. This dual-pronged strategy minimizes reliance on a single data source, thereby enhancing the overall resilience and reliability of the pricing mechanism.

4.2 Verification solution

4.2.1 Static acceptable_range

The solution introduces a static method, acceptable_range, to address potential vulnerabilities when relying solely on the Curve Oracle. While the prices generated by the Curve Oracle may be more accurate than Chainlink, it could be susceptible to manipulation. Chainlink, on the other hand, is robust and tested, considered a safer choice in the industry. When the difference between Curve Oracle and Chainlink exceeds a fixed value, the acceptable_range serves as a threshold to switch to the Chainlink feed.

Strategically, the acceptable_range accepts quotes that are within ±1% of the Chainlink quotes. This is nearly three standard deviations away from the average difference between Curve and Chainlink, considering the improved stETH/ETH and ETH/USD feeds compared to the previous stETH/USD feed.

4.2.2 Function output derived_price

The derived_price is a function or mechanism designed to determine the final quote for a given asset, especially in scenarios involving the Curve Oracle and Chainlink Oracle.

In the described solution, this function evaluates quotes from both the Curve Oracle and Chainlink Oracle. Based on the observed difference between these two prices and whether it falls within or exceeds the predefined accepted_range, the function outputs different derived prices.

Here is a comparison of derived_price with the other price sources previously displayed:

BOT profits can be visualized by this derivative price (since there is no deviation, this price will be exactly equal to Curve stETH/ETH and CL stETH/ETH) as shown below:

Analyzing total profits can reveal the bigger picture. Six outliers were identified and the total profit for each case was calculated before and after filtering the outliers.

Curve stETH/ETH and Uniswap ETH/USDC perform the best in reducing the available profit for BOTs. The derived_price they provide has the same profit potential as the current stETH Oracle implementation but limits the profit, assuming it saves users approximately 35.4 ETH across the analyzed 189 transactions.

4.3 Conclusion

Due to the heavy reliance on quotes from the most liquid decentralized exchanges for on-chain activities and the fact that MEV bots also follow the same quotes when exchanging mkUSD for LSD, the accuracy of quotes (used for pricing redemptions by the Oracle) is of paramount importance.

Historical data suggests that the Curve pool Oracle prices are closer to the reference (UniswapV3 price data) compared to Chainlink prices. The data indicates that implementing Curve Oracle would reduce MEV for bots and provide better exchange rates for users redeeming their treasures.

While using Curve Oracle as a standalone Oracle might be tempting, the effectiveness of Curve price feedback depends on the liquidity depth of specific assets and interaction with the pool. A hybrid Oracle solution with Curve Oracle and Chainlink Oracle can be used to match on-chain prices while retaining the reliability and broad market coverage inherited from Chainlink Oracle.

The hybrid Oracle solution we propose evaluates the standard deviation (SD) to generate derived_price. If the SD approaches 0, it indicates adherence to the derived_price reference values, making it worth considering. This ensures that when Curve Oracle deviates from predefined thresholds, the solution dynamically switches to the safer Chainlink source. As this solution almost always outputs stETH’s Curve quote, it is assumed that MEV activity is the same as using Curve stETH/ETH, with no fallback.

Appendix A: Data Processing Scripts

The scripts used to generate the analysis in this report are as follows:

  1. OracleAnalysisV4: Colab notebook for data collection
  2. OracleAnalysisPlayground: Colab notebook for plotting charts using pickle data files
  3. PrismaOracleModelingV1: Colab notebook for plotting MEV exchange activity charts
  4. DerivedPriceModeling: Colab notebook for testing and modeling alternative Oracle solutions

Appendix B: rETH/cbETH residual analysis

Other Charts rETH

Chainlink and Curve

Uniswap and Curve

Uniswap and Chainlink

Check peak rETH

在观察期间,rETH 曲线预言机价格出现了几次峰值。这导致预言机价格和现货参考之间的价格偏差激增。下面是更详细的图表,显示了几次价格飙升期间的资金池比例/代币流动性以及预言机价格的行为。

start_block = 18824000

end_block = 18827000

interval_blocks = 100

Mining pool ratio:

Oracle price:

start_block = 18850000

end_block = 18858000

interval_blocks = 100

Mining pool ratio:

Oracle price:

start_block = 18880000

end_block = 18885000

interval_blocks = 100

Mining pool ratio:

Oracle price:

Other Charts cbETH

Chainlink and Curve

Uniswap and Curve

Uniswap and Chainlink

Check Peak cbETH

During the observation period, the cbETH Curve Oracle prices experienced several peaks. On several occasions, this resulted in significant spikes in the price deviation between the Oracle price and the spot reference. Below is a more detailed chart showing the behavior of the liquidity pool ratios/token liquidity during these periods of price surges and the behavior of the Oracle prices.

start_block = 18693500

end_block = 18696000

interval_blocks = 10

Mining pool ratio:

Oracle price:

start_block = 18814000

end_block = 18816500

interval_blocks = 10

Mining pool ratio:

Oracle price:

start_block = 18800000

end_block = 18805000

interval_blocks = 10

Mining pool ratio:

Oracle price:

Statement:

  1. This article is reproduced from [marsbit], original title “Comparative analysis of Prisma optional oracles”, the copyright belongs to the original author [PrismaRisk], if you have any objection to the reprint, please contact Gate Learn Team, the team will handle it as soon as possible according to relevant procedures.

  2. Disclaimer: The views and opinions expressed in this article represent only the author’s personal views and do not constitute any investment advice.

  3. Other language versions of the article are translated by the Gate Learn team, not mentioned in Gate.io, the translated article may not be reproduced, distributed or plagiarized.

Comece agora
Inscreva-se e ganhe um cupom de
$100
!