Skip to main content

How Is a TWAP Implemented on a Blockchain That Only Records Discrete Transactions?

A TWAP is implemented by a smart contract that periodically records the asset's spot price and the time of the recording. The contract then calculates the average by summing the product of each recorded price and the time elapsed since the previous recording, and dividing this total by the overall time window.

This effectively reconstructs the time-weighted average from the discrete on-chain data points.

What Is a Time-Weighted Average Price (TWAP) Oracle and Why Is It Used?
How Is the Interest Rate of a Floating-Rate Smart Bond Determined and Updated by the Contract?
How Does a Volume-Weighted Average Price (VWAP) Differ from a Simple Average in Settlement?
What Is a Volume-Weighted Average Price (VWAP) and How Does It Differ from TWAP?