Pyth Oracles Land on Mars

Mars Protocol
8 min readJun 30, 2023

--

Mission briefing:

  • Mars Protocol has successfully transitioned from TWAP-based oracles to Pyth oracles
  • Discover the challenges with TWAP-based oracles and how Pyth offers an alternative solution for price-feed data
  • Learn how this shift enhances the security and efficiency of the Mars ecosystem

Accurate asset pricing is the lifeblood of Mars. It forms the basis for all transactions including lending and borrowing. Since its inception, Mars Protocol has relied on Time-Weighted Average Price (TWAP)-based oracles to value assets. However, TWAP-based oracles, while reliable, have presented challenges that require Mars to evolve. Today, Martians embark on a new journey with the integration of Pyth Network’s advanced oracles. This radical change resets Mars’ reference assets from OSMO to USD and could ultimately usher in support for off-chain assets on Mars. Let’s explore how.

Understanding the TWAP-Based Oracle System

TWAP-based oracles function by taking the average price of an asset over a certain period of time. This price calculation mitigates the impact of short-term price volatility and provides a more stable pricing mechanism for assets. While resilient and completely on-chain, TWAP-based oracles also have several vulnerabilities, which are explored below.

Price Manipulation Attacks

Price manipulation attacks typically occur when malicious entities influence the market price of an asset to exploit the oracle’s price feed for their own gain, often resulting in bad debt for the protocol. TWAP-based oracles are particularly susceptible to manipulation. In scenarios where on-chain liquidity for a pool is insufficient, the cost for an attacker to manipulate the TWAP price becomes relatively low. By strategically placing trades, they can artificially inflate or deflate the price of an asset. This manipulation can create a discrepancy between the oracle’s price feed and the actual market price, opening up opportunities for an attack.

Furthermore, since TWAP-based oracles cannot aggregate off-chain price sources, they can be relatively cheaper for an attacker to manipulate compared to alternatives. This combination of factors makes TWAP-based oracles a prime target for price manipulation attacks.

Capital Efficiency

To mitigate price manipulation attacks, protocols using TWAP-based oracles often have to resort to more conservative parameters. This conservatism, while potentially effective in mitigating such risks, can come at the expense of capital efficiency. Higher amounts of liquidity are required to buffer against the expense and profitability of attacks. This constrains the protocol’s scalability and efficiency.

Moreover, the capital inefficiency resulting from TWAP-based oracles can pose a barrier to protocol growth and adoption. Without the ability to price in-demand assets, which may not meet more conservative liquidity requirements, the protocol may struggle to attract liquidity and grow.

Concentrated Liquidity

The integration of TWAP-based oracles with concentrated liquidity pools presents significant challenges. In contrast to traditional AMMs where liquidity is uniformly distributed across all prices, concentrated liquidity models are more dynamic with liquidity density changing based on the distribution of user-specified price ranges. Given that TWAP-based oracles average the asset price over a certain period, this dynamic and localized variation in liquidity can introduce a level of volatility and potential distortion into the TWAP. The fluctuation of the price within the oracle could therefore be out of sync with wider market movements, making it less reliable as a true reflection of an asset’s value.

Furthermore, the potential for new price manipulation attacks increases as malicious actors could exploit the varying liquidity depths by placing trades that specifically target less liquid price ranges. As such, justifying the cost of potential attacks against these types of pools becomes increasingly difficult.

This is especially crucial for Mars given that its premier outpost on Osmosis is in the process of migrating its constant product pools to concentrated liquidity pools, emphasizing the need for more robust oracle solutions.

Pythnet as an Alternative Oracle Solution

Embracing the future, the Martian Council has chosen Pythnet as its new oracle solution for pricing assets. Pyth is a sophisticated oracle network that supplies real-time, high-fidelity data feeds.

Multiple Price Feeds

Pyth stands out with its capacity to utilize multiple price sources. This enhances its robustness against price manipulation attacks by making it more expensive and less profitable to exploit.

A distinctive advantage of Pyth oracles is the ability to integrate a TWAP oracle as one of the price feeds, provided it satisfies the required standards. This allows Pyth to inherit the stability and resilience of TWAP-based oracles while also leveraging the benefits of a diversified data source.

Asset Offerings

Unlike TWAP-based oracles, Pyth’s security doesn’t rely on a single price source or high liquidity on-chain to ensure accurate price feeds. This feature allows for the listing of more ‘long-tail’ assets, which might not be available in a conservative lending market using TWAP-based oracles. In addition, Pyth’s ability to utilize off-chain price feeds opens up the exciting possibility of integrating off-chain assets into Mars Protocol. This could dramatically broaden the Mars Protocol’s scope and usher in an entirely new class of assets into its ecosystem.

Capital Efficiency

TWAP-based oracles, in their efforts to ensure security and mitigate price manipulation risks, often necessitate the implementation of more conservative parameters on assets. One such parameter could be a lower loan-to-value (LTV) ratio, especially for assets with lower liquidity. While this conservatism effectively helps secure the protocol, it also requires more capital to grow and limits the protocol’s flexibility to support a wider range of assets.

In contrast, Pyth’s oracle solution is designed to reduce dependence on on-chain liquidity. Pyth can aggregate price data from multiple sources, both on-chain and off-chain, effectively diluting the influence of liquidity on any single market and reducing susceptibility to price manipulation. As a result, the protocol could allow higher LTV ratios or less conservative parameters.

Pyth Advanced Features

By default, Pyth incorporates a staleness check, which can cause a query for the current price to fail if too much time has elapsed since the last update. This mechanism is designed to help integrators avoid inadvertently using a stale price, serving as a significant safeguard against outdated price information.

In the future, Pyth could potentially utilize other advanced features such as confidence intervals and EMA/Spot divergence. These features could further enhance the robustness of the oracle system and help mitigate some common concerns associated with TWAP-based oracles.

The Road Ahead for Mars

The integration of Pyth into the protocol presents an opportunity for Mars to refine and strengthen its oracle mechanisms, thus ensuring greater accuracy and reliability in asset pricing. This integration involves two significant changes.

The first relates to Mars’ base asset. Previously, Mars operated with OSMO as the reference asset, providing the base value against which all other assets were compared and valued. However, given that Pyth price feeds are denominated in USD, the normalization asset has been revised accordingly.

The second change relates to the specific oracle implementations for each asset. Note that as not all assets are supported by Pyth, a hybrid implementation (where a TWAP and a Pyth-based feed are used) is needed for some.

The following chart shows the new implementation for each asset currently listed on the Red Bank:

Some additional notes for specific assets:

  • axlUSDC, axlWETH, and axlWBTC: The new oracle implementation utilizes the price of the underlying asset instead of the bridged asset. This approach has notable implications. If an incident impacts the bridge — for instance, a loss of assets — Mars would remain unaware of this development, continuing to price bridged assets at the underlying asset’s value. This scenario could expose the protocol to potential losses. It’s a known but considerable risk, and Mars’ current implementation should be regarded as a temporary measure. In the future, the protocol could aim to adopt a more robust implementation incorporating a bridge “proof of reserves” mechanism. However, with Axelar’s widespread adoption in the Cosmos, and a long track record of security for bridged assets, the Martian Council has deemed the risk minimal enough to proceed.
  • stATOM: A hybrid implementation is necessary since Pyth doesn’t offer an stATOM/USD feed. Stride is in the process of deploying a redemption rate contract on Osmosis, which would enable the migration to a redemption rate-centric approach. As soon as the Stride contract becomes operational, the protocol could be upgraded to proceed with updating the current implementation.
  • AXL: Similar to stATOM, a hybrid implementation is required since Pyth doesn’t currently offer an AXL/USD feed. However, Pyth is actively working on this addition. Once it becomes available, the protocol could be upgraded to transition the current implementation exclusively to Pyth.

With these changes, Mars can expect a significant enhancement in capital efficiency and scalability, opening the door to listing more diverse assets and increasing the resilience of the protocol against potential attacks. Notwithstanding, the adoption of this new oracle solution does come with certain challenges and adjustments, especially for specific assets.

A protocol’s success is intimately linked with its ability to innovate rapidly and often. Mars is engineered to create the best lending and leverage platform for Martians everywhere. Evolving the protocol’s oracle is merely the first step in exploring the untapped potential that lies ahead.

🔴

Follow Mars on Twitter, join the Mars Discord for community support, and subscribe to Mars’ email newsletter for the latest updates from Mission Control.

About Mars

Mars is a novel interchain credit protocol primitive facilitating non-custodial borrowing and lending for the Cosmos ecosystem and beyond. Its hub and outpost architecture allows Mars to operate on any chain in the Cosmoverse, and enables a new primitive: the Rover. Rovers can give their pilots DeFi superpowers to engage in virtually every governance-approved activity they might encounter on a centralized exchange: spot trading, margin trading, lending and borrowing — all in a single decentralized credit account represented by a transferable NFT. Explore it now at marsprotocol.io or in the Mars v2 Whitepaper.

DISCLAIMER

Engaging in leveraged transactions may be legally restricted in some jurisdictions–please consult your own legal counsel and adhere to your local laws/regulations. Remember, Cosmos, Osmosis, and Mars are experimental technologies. This article does not constitute investment advice and is subject to and limited by the disclaimers and other information contained or referenced in the Mars FUD Bible which you should review before interacting with the protocol.

Jump Crypto, which has interests in Pyth, is an investor in Delphi Labs, which contributes to Mars Protocol. Delphi Ventures shares certain managers & owners with Delphi Labs and is an investor in Pyth.

This message is qualified by the Mars Disclaimers/Disclosures.

--

--