Oracles and Price | Integral TWAP
This blog post explains the working mechanism of Integral TWAP's oracle.
This post explains the working mechanism of swapping on Integral TWAP, and summarizes the main benefits you can draw from using this product over interacting with decentralized exchanges or aggregators for your large orders.
Time-Weighted Average Price (TWAP) is a trading algorithm based on weighted average price used to execution of bigger orders without excessive impact on the market price.
The most common use of TWAP is for distributing big orders throughout the trading day. Let’s say you want to buy 100,000 ETH. Putting one such a big order would vastly impact the market and the price most likely would start to raise. To prevent that, trader can define time period in TWAP Strategy over which they want to buy ETH. It will slice evenly big order into smaller sub-ones and execute them over defined period. The TWAP price of the large order will be the arithmetic mean (average) of the prices used to execute these sub-orders.
TWAP is highly used to minimize a large order's price impact and result in price improvement, because:
TWAP is extremely useful for large orders, as the strategy minimizes price impact. However, before Integral TWAP, it is not economic to perform the strategy on-chain because:
Therefore, Integral TWAP introduces a new design that delivers the same price-impact-mitigating effect just like traditional TWAP, without the need to split your orders and pay for extra fees.
Once the order is submitted, it will wait in the smart contract contract for 30 minutes before interacting with the pool. During this time, the protocol will pick up price information from the Uniswap V2 oracle, and calculate TWAP. After 30 minutes elapses, the protocol will execute the whole order at TWAP.
TWAP is mathematically defined as the arithmetic mean of the prices in a period. Suppose 1 ETH = 4,100 USDC on block #1, 4,110 USDC on block #2, and 4,105 USDC on block #3, TWAP for these 3 blocks is (4,100 + 4,110 + 4,105) / 3 = 4,105 USDC.
DEXs like Uniswap relies on curves to deduce price between two assets based on their amounts in the pool. A large swap will both increase and decrease the amount of assets, thus changing the ratio/price substantially and resulting price impact.
This does not apply to Integral TWAP, whose prices is solely determined by the oracle. Even if a large order does change the ratio between two assets, it will not affect the TWAP used to execute the order.
The curve of Integral TWAP is actually a flat line. It creates the effect that the WHOLE liquidity of the pool is concentrated on the price point of TWAP. In theory, you can even swap all the liquidity out of the pool with 1 single TWAP.
Integral TWAP is for everyone who would like to get a trade executed at the next 30-min TWAP. Whether you are a long-term investor, a HODLer, a day trader, or a farmer, with Integral TWAP:
However, saving with Integral TWAP would be the most when you have a large order to execute.
TWAP can help you minimize price impact, but it also exposes you under the risk of price volatility. Therefore, it is very important to get a proper estimation of how much you'll get from the trade, and tells the protocol when to stop if the execution price really diverges from your expectation.
When you input an amount into Integral TWAP, the system will display an estimated amount that you may receive through 30 min TWAP. The estimation is calculated based on the current Uniswap v2 spot price, and does not take price impact into consideration.
The Estimated Amount = Amount of Input Token * (1-0.1%) * Uniswap Spot Price
Due to market movement, there will always be some difference between the TWAP and the spot price when you submit the order, and sometimes you may get fewer tokens from TWAP.
Located at the bottom of the swap interface, the Minimum Received corresponds to the worst-case scenario for your trade. After 30-min wait time elapses, if the actual amount of tokens you'll receive is less than Minimum Received, your order will be reverted to protect your funds.
Minimum Received = Estimated Amount * (1 - Slippage Tolerance)
The default slippage tolerance is 0.5%, and you can change it in the Advanced Settings (gear icon). However, we suggest you to only change it when the market is highly volatile and your order keeps being reverted.
*Manually splitting orders could possibly reduce the price impact, but it's hard to perform due to the fact that trader lacks the knowledge of when and how liquidity in the pool will be improved by LPs. Also, it's prone to sandwich attack.
** The current gas estimation of a swap on Integral TWAP is 50,000 GWEI.
*** Integral TWAP has low/no risk for getting sandwich attack because it is very difficult for non-atomic trade to get affected by sandwich attacker and flashloans, and oracle for a large pair is very hard to manipulate.