Blockchain & Cryptocurrency Glossary

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

  • search-icon Clear Definitions
  • search-icon Practical
  • search-icon Technical
  • search-icon Related Terms

Time-weighted Average Rate (TWAR)

1 min read
Pronunciation
[time-weyt-ed av-er-ij reyt]
Analogy
Think of TWAR like averaging hourly electricity rates over a month to determine your final bill.
Definition
A method to calculate the average interest or exchange rate over a period, weighting each rate by the time it was in effect.
Key Points Intro
TWAR computes averaged rates for financial protocols based on time duration.
Key Points

Rate sampling: records rate and timestamp at each change

Weighted average: multiplies each rate by its duration

On-chain storage: accumulators track cumulative rate*time

Use cases: interest accrual and dynamic fee calculations

Example
A lending protocol uses TWAR to calculate borrower interest over a week by sampling the variable rate each hour and weighting by duration.
Technical Deep Dive
Contracts maintain `cumulativeRate` and `lastUpdateTimestamp`. On each rate change: `cumulativeRate += currentRate * (now – lastUpdateTimestamp)`. TWAR = `cumulativeRate / (now – startTimestamp)`. Fixed-point arithmetic (e.g., UQ112x112) ensures precision.
Security Warning
Sparse sampling during rapid rate changes can misestimate effective yields.
Caveat
Higher sampling frequency improves accuracy but increases gas costs.

Time-weighted Average Rate (TWAR) - Related Articles

No related articles for this term.