LogoLogo
  • What Is Elephant Money?
  • Overview
    • Using The Wiki
  • Ecosystem Tokens
    • ELEPHANT
      • Fees - Detailed
      • Economics
      • Elephant Buyback System
    • TRUNK token (Elephant Money Stable)
      • Deflationary Mechanics
    • SVNN token (Savanna Haus)
      • Details
  • Services
    • Elephant Money Futures Vaults
      • Futures Key Features
      • System Wide - Dynamic Rate Scaling
      • Base Rate & The BNB Reserve
      • Personal Rate
      • Futures Deposit & Claim Mechanics
      • Futures Maxes, Limits & Payouts
      • Individual Account - Adaptive Rate Limiters
    • Unlimited NFT's
      • Key Features
      • Minting Batches
      • Mint, Rewards & Claim Mechanics
      • Rewards
      • NFT Marketplace
    • TRUMPET
      • TRUMPET - How It Works
      • Trumpet Features
      • TRUMPET Token - Additional Details
      • Token Mechanics - Mint & Redeem
        • TRUNK Buyback Strategy
  • Price Stability Formula
    • Liquidity Management (Stability)
    • ELEPHANT Token Supply Management System (Growth)
    • Token Holder Distribution
    • Circulating Supply
  • Tokenomics
    • Launch & Initial Token Distribution
    • The Graveyard (GY)
      • The Graveyard Rebalanced Event
    • Buy with Bertha (BWB)
  • Elephant Money Treasury System
    • Elephant Treasury (BERTHA)
      • BERTHA - How It Is Funded
      • BERTHA - Responsibilities
    • BNB Reserve
      • BNB Reserve - How It Is Funded
      • BNB Reserve - Responsibilities
    • BTC Turbine
      • How It Is Funded
      • Responsibilities
    • TRUNK Turbine
      • How It Is Funded
      • Responsibilities
  • Liquidity
    • ELEPHANT/BUSD LP
    • ELEPHANT/WBNB LP
    • TRUNK/WBNB LP
    • TRUNK/BUSD LP
  • How To Guides
    • How To Deposit Into Futures
    • How To Buy / Sell / Transfer ELEPHANT
      • Buy / Sell via PCS (10% Transcation Fee)
      • Buy With Bertha (8.5% Transcation Fee)
    • How To Mint & Stake Unlimited NFT's
    • How To Mint & Redeem TRUMPET
  • Navigating The Website
    • ELEPHANT
      • Balance (Overview Tab)
      • Stake % (Overview Tab)
      • Price - SA (Elephant Stats)
      • Graveyard (Elephant Stats)
      • Liquidity (Elephant Stats)
    • Unlimited NFTs
      • Main Dash
      • Overview Section
      • Staking Section
      • Marketplace
    • Elephant Money Futures
      • Available
      • Total Value
      • Claimed
      • TVL (Overview Tab)
      • Participants (Overview Tab)
      • Total Deposited (Overview Tab)
      • Total Claimed (Overview Tab)
      • Available Sweep (Overview Tab)
      • Daily Liabilities (Yield Tab)
      • BNB Reserve (Yield Tab)
      • Daily Yield (Yield Tab)
    • TRUMPET
      • TRUMPET holdings
      • TRUNK Balance (TRUMPET)
      • Get Trumpet (Button)
      • Price (TRUMPET)
      • Supply (TRUMPET)
      • Backed Supply (TRUMPET)
      • Participants (TRUMPET)
    • The HERD Partner Network
      • Partner Network Dashboard
      • Partner Tab (HERD)
      • Stats Tab (HERD)
      • Checker Tab (HERD)
  • Security
    • Protecting Against Flash Loan Attacks
    • TWAP Oracle
    • Audits
  • Referral Program
    • The HERD Partner Network
      • Buy With Bertha Partner Rewards
  • Glossary
    • RFI Rewards
    • Bertha
    • AMM
    • (3,3)
    • Rainy Day Fund
  • OFFICIAL LiNKS
    • Website
    • Socials
    • Contract Network
    • Analytics Dashboards
    • Shop
    • Community Links
      • Tools
      • Calculators
      • Content
        • Youtube Channels
        • Medium Writers
Powered by GitBook
On this page
  • Understanding Attack Vectors
  • How It Works
Export as PDF
  1. Security

TWAP Oracle

Understanding Attack Vectors

Spot price oracles (provided by AMM DEX LPs) calculate the price of an asset by simply dividing the amount of the asset against another asset in a two-asset liquidity pool.

The problem with this approach? An attacker could drain liquidity from one side of the pool using a flash loan and thus trigger the price oracle to quote an abnormally high price for an asset. Since flash loans are typically borrowed without any collateral, spot price oracles become targets of risk-free manipulation attempts.

To mitigate this sort of attack Elephant Money has implemented a TWAP (Time-Weighted Average Price) oracle.

How It Works

A TWAP oracle is programmed to measure prices over long pre-set "time" intervals helping to protect to some degree against flash loan attacks. For example, if the algorithm is set to a 4H interval for the TWAP oracle, the latter returns the average price of the asset across the last 4 hours.

TWAP oracles are designed to solve a problem associated with using on-chain oracles: price manipulation.

A weighted average simply means that values in a dataset are multiplied by predetermined “weights” before being summed up as part of the calculation. Weighting assigns significance to certain values in a distribution and is thus considered more accurate than naively summing up all values and dividing by n number of values to get the average of a dataset.

A TWAP oracle uses duration (time) as a weight. The price (P) is continuously multiplied by how long it lasts for (T) and added to a cumulative value (C) at different checkpoints (usually at the end of a block). In the end, the total cumulative value is divided by the total duration to get the average price across the specified period.

Since the TWAP algorithm derives price from an average of multiple prices across a pre-set time interval from the previous block(s); this rules out the single-transaction exploit where an attacker drains liquidity via a flash loan and promptly sells an asset at an inflated price in the same transaction (block).

PreviousProtecting Against Flash Loan AttacksNextAudits

Last updated 1 year ago