Yellow Capital Blog/Investments/TWAP vs. VWAP Pricing Techniques

TWAP vs. VWAP Pricing Techniques

Sunday, March 31, 2024

Algorithmic orders for decentralized finance (DeFi) applications are time-weighted average price (TWAP) and volume-weighted average price (VWAP). This discursive will attempt to delineate the differences in TWAP and VWAP methodologies and operational principles within blockchain ecosystems while touching on the benefits and possible drawbacks. Critical, then, for DeFi projects is to have a very good appreciation of these differences, either in the security architectures for deployment or in their integration capabilities, so they give end-users exact, reliable, fair pricing.

Understanding TWAP

WAP stands for Time Weighted Average Price. The formula allows one to compute an averaged value an asset has carried over a duration he specifies. The most common use case of TWAP could be found in the DeFi space on decentralized exchanges (DEXs), particularly automated market makers (AMM), in the determination of prices of assets that would be used under various protocols. TWAP not only serves as a pricing mechanism but also a trading strategy designed for the distribution of large orders into smaller pieces gradually over time, to reduce market impact. The context of this article is about pricing rather than the trading strategy.

TWAP Calculation Process

The TWAP value is obtained by summing up asset prices at several instances within a predetermined timeframe and dividing the aggregate by the total count of these instances.
A typical TWAP formula is expressed as:

TWAP = (TP1 + TP2 + ... + TPn) / n,
where TP1 denotes the price at the initial time point, and n signifies the cumulative number of time points.

For instance, to determine the TWAP of an asset within a minute using 15-second intervals, if the prices were $100 at the start, $102 at 15 seconds, $101 at 30 seconds, $98 at 45 seconds, and $103 at the end, the TWAP would be the sum of all these prices divided by the total number of timepoints (five), yielding a TWAP of $101.

TWAP Advantages

Due to its simplicity and minimal computational requirements, TWAP is straightforward to implement and execute on-chain, making it an efficient option.

Safeguard Against Flash Loan Exploits

Flash loans are instant, uncollateralized loans that must be repaid within the same transaction, posing a risk of exploitation in dApps that utilize AMM DEXs for spot pricing in liquidity pools. Malicious entities can exploit this by securing large loans in a single transaction to skew the spot price, thereby compromising smart contracts that depend on these spot prices.

Employing TWAP, derived from multiple block prices from AMM DEXs, offers a protective mechanism against such flash loan maneuvers.

Exploring VWAP

VWAP averages the price of each aggregated from various trading platforms, thus adjusted by the corresponding volumes of those trades. At the center of Chainlink Price Feeds, used by leading Oracle solutions across the industry, is VWAP: most often used by DeFi protocols.

The other most popular use of the VWAP calculation approach is its use by traders as a technical indicator and by brokers as an execution strategy in traditional finance. This is a discussion of its application as a pricing mechanism.

VWAP Calculation Methodology

The Volume Weighted Average Price (VWAP) is derived by aggregating the trading prices of an asset across various platforms, weighted by the transaction volumes at each venue, excluding volumes from wash trades and other anomalous activities.

A typical formula for VWAP is:

VWAP = (Σ(Vi x Pi)) / Σ(Vi), where:
1. Vi represents the volume at which the asset was traded in the i-th trading venue, and
2. Pi is the corresponding trading price at that venue, with the summation extending over 'n' different trading environments.

For illustrative purposes, consider the VWAP calculation for a hypothetical asset within a given period: Suppose 100 tokens were exchanged at $101 on platform X, 150 tokens at $102 on platform Y, and 500 tokens at $100 on platform Z. Multiplying each price by its associated volume (100 x 101 + 150 x 102 + 500 x 100) and dividing the total by the aggregate volume (100 + 150 + 500) yields a VWAP of $100.53, from a total of 75,400/750.

VWAP Benefits

Market Span

VWAP offers a comprehensive market price, representing the asset's value across a spectrum of trading venues, from minor to major exchanges. It effectively filters anomalies in less liquid markets prone to manipulation, emphasizing regions with greater trading activity. This ensures the derivation of a market-wide price and is adaptable to liquidity shifts across different venues.

Precision and Currency of Data

VWAP leverages data from numerous trading venues, furnishing users with a price metric that more accurately mirrors the global demand and supply for the asset. This up-to-date data allows VWAP-based prices to closely align with the prevailing market-wide asset valuation.

Resistance to Manipulation

Due to its comprehensive market integration, VWAP is less susceptible to manipulation by individual or financially robust malicious entities, including flash loan assaults. To significantly impact VWAP, an adversary would need to influence the trading dynamics across the majority of the asset's markets, thereby affecting the asset's overall market price.

Indicator Delays

TWAP relies on historical price data, positioning it as a delayed indicator. This delay can cause discrepancies with the current market-wide prices, particularly during volatile periods, potentially leading to exploitation opportunities. While shortening the TWAP calculation period can mitigate this lag, it also lowers the cost of potential market manipulations by well-funded adversaries.

Market Representation

The scope of market representation for a pricing mechanism is critical. On-chain TWAP calculations typically draw from a singular trading environment, not capturing the asset's valuation across the diverse landscape of centralized and decentralized exchanges. This limitation is particularly relevant in DeFi, where DEX protocols may operate concurrently in various versions across multiple blockchains.

Thus, TWAP is more vulnerable to manipulation through a single exchange due to fragmented liquidity, which requires less capital for a successful attack. Moreover, liquidity can fluctuate, offering no assurance of sustained liquidity levels at an exchange previously utilized for TWAP data.

Conversely, impacting VWAP necessitates market-wide manipulation, as VWAP algorithms integrate data from all trading venues, including both centralized and decentralized exchanges (CEXs and DEXs), ensuring a robust and comprehensive asset pricing reflective of global market activity.

Security Scalability

On-chain TWAP mechanisms face inherent constraints in bolstering their security. Lengthening the timeframe for gathering price points can indeed enhance resistance to tampering, yet it detracts from the immediacy of the data, thereby diminishing its precision. This creates a fundamental trade-off between a TWAP mechanism's security and its accuracy, making it challenging to perfect both simultaneously.

The most feasible strategy for augmenting the security of conventional on-chain TWAP mechanisms is to boost the market liquidity/volume being monitored. This approach raises the financial barrier for potential attackers looking to manipulate the market.

In contrast, VWAP algorithms, when applied to supplying market data for DeFi platforms, are capable of strengthening their security through various means without sacrificing price precision. Effective strategies for enhancing security encompass the addition of more data sources to mitigate risks of centralization and shield against API failures, the employment of premium data providers to filter out anomalies and dubious trading patterns, and the adoption of crypto economic rewards.

Asset Diversity

DeFi protocols that rely on on-chain liquidity pools for TWAP price generation are confined by the range of assets available on their trading platform. This inherently limits them to the tokens that exist on the specific blockchain they operate on. For instance, protocols based on Ethereum can only produce TWAP prices for ERC-20 tokens that are traded against other tokens within the same network.

On the other hand, the Chainlink Network enables DeFi protocols to access VWAP pricing information not just for native digital assets within the Web3 ecosystem but also for a broad spectrum of traditional assets, including various currencies, commodities, and synthetic assets, along with direct pricing against fiat currencies.

Vulnerable to Multi-Block Attacks

DeFi protocols employing on-chain TWAP pricing on proof-of-stake blockchains are exposed to the risk of multi-block MEV attacks. Unlike manipulating immediate prices within a single transaction in an AMM DEX, as seen in flash loan attacks, these strategies involve altering prices over several consecutive blocks. This vulnerability arises when an attacker with a substantial stake intermittently gains control over the validators responsible for consecutively publishing blocks, coupled with the predictability of future block validators.

Leveraging VWAP With Chainlink Price Feeds

While the Chainlink Network is equipped to support various pricing methods, including TWAP, it predominantly employs a VWAP (Volume Weighted Average Price) mechanism for its Price Feeds due to its robustness, resistance to manipulation, and overall reliability in providing market data.

This approach draws on a diverse pool of reputable data providers to offer VWAP-based pricing information for a broad spectrum of assets. This infrastructure is crucial for the decentralized finance (DeFi) sector, offering dependable market data that remains precise even during turbulent market conditions. It allows for the retrieval of up-to-date asset pricing, which can be utilized within smart contracts on the blockchain or in external applications, minimizing reliance on trust.

Chainlink Price Feeds function as on-chain reference contracts, maintaining a record of both current and historical price information for assets, refreshed by decentralized oracle networks (DONs). These networks are comprised of independent node operators, bridging the gap between blockchains and external systems, a fundamental component for the integration of real-world data into smart contracts. This capability is pivotal for a multitude of applications within the DeFi space, including but not limited to, lending platforms, stablecoins, derivative instruments, synthetic assets, and insurance products.

By September 1, 2022, Chainlink Price Feeds had contributed over 4.2 billion data points directly on the blockchain, supporting more than 1,470 projects and securing a significant value in the tens of billions of dollars, underscoring their integral role in the DeFi ecosystem's infrastructure.


Precise and secure price information is crucial for the integrity and success of DeFi platforms, guaranteeing fair asset valuation and safeguarding against price manipulation by malevolent entities. VWAP (Volume Weighted Average Price) methodologies tend to be more appropriate for a wide array of DeFi applications in comparison to TWAP (Time Weighted Average Price) strategies.

Chainlink Price Feeds offers a dependable solution by providing access to VWAP-based pricing data. This data is not only accurate and resistant to tampering but also decentralized across various layers, ensuring a robust framework for users and projects alike, and contributing positively to the broader DeFi ecosystem.

Yellow Capital

Your Partner For Success

customer1 png

Hi, I am Alexis Yellow

Chairman of Yellow Capital

Are you ready for a wild career transition? I went from launching rockets into outer space at the European Space Center to helping Token Issuers launch their Crypto Projects!

Yellow Capital provides advisory services, strategic investments, and prime crypto market making.

Join me on this journey as I share my experiences and expertise in the crypto world, and maybe we'll even launch a few successful projects together!

1 png


Private Rounds

- Early stage pre-listing
- Investment and Incubation

Market Making

Token Issuers

- We are Prime Market Makers for the projects we invest into.

Increase Your Cash Flow

Listed Tokens

- We buy up to $5,000,000

Exclusive For the Projects We Invest In

Get Free Market Making

Our investment strategy involves providing deep liquidity crypto market making to the projects we invest in. This approach allows us to ensure continuous and substantial liquidity in exchanges. By doing so, we aim to increase market efficiency and reduce price volatility. We help to stabilize prices and reduce the bid-ask spread, which can lower transaction costs for traders. This usually attracts more traders to the markets, by making it easier and less risky to trade your token which can help to increase the overall liquidity and trading volumes both for the benefit of traders and issuers. However, we recognize that providing liquidity also comes with potential risks, which we carefully evaluate and manage as part of our investment decision-making process.