Skip to main content

What Are the Computational Overheads Associated with Calculating a TWAP On-Chain?

Calculating a TWAP on-chain requires storing a history of price points and timestamps, and then performing the weighted average calculation in a smart contract function. This increases the gas cost for every oracle update and every time a protocol reads the price.

For long TWAP windows, the storage and computation costs can become significant, potentially limiting the frequency of updates.

What Is the Role of the ‘EVM’ (Ethereum Virtual Machine) in Gas Consumption?
What Is the Difference between a ‘Gas Limit’ and ‘Gas Price’ in Ethereum?
What Is a ‘Gas Limit’ and Why Is It Necessary for Smart Contracts?
What Is a “Gas Limit” in the Context of Transaction Fees on a Network like Ethereum?