banner

October 16, 2023

Deep Dive: Onchain Dynamic pricing engine

As we approach closer to the launch of Flash.trade, we wanted to highlight all the novel mechanisms we have built that are only possible on Solana. For our first deep dive blog we begin explaining about Flash’s on-chain dynamic pricing engine that is designed to dynamically quote assets of the Flash Liquidity Pool (FLP) all while maintaining profitability irrespective of market conditions.

Flash uses Pyth network as its main oracle to determine asset prices and has designed a one-of-a-kind pricing engine that dynamically quotes prices according to volatile market conditions. Before we explain the engine we would like to give a shoutout to the chads at Pyth for establishing the industry benchmark and publishing parameters that allow protocols to fully determine pricing on-chain without the need of any external parties. This makes it possible for protocols to be truly decentralised and autonomous. These on-chain parameters enable Flash’s dynamic pricing function and we’d like to highlight some of them before delving deeper into how it works.

Pyth’s on-chain parameters

  1. Confidence interval: This is a novel parameter published by pyth which gives an accurate measure of uncertainty around the price that is aggregated from wide range of pyth’s data providers. This parameter helps protocols to incorporate pricing uncertainty and help developers/protocols to take price premiums/discounts into account.
  2. EMA: This is one of the most underrated parameters and don’t go by its name since it is not a simple exponential average. The folks at Pyth significantly improved EMA just for Solana and built this superior lagging indicator that takes into the size of the confidence interval to give prices that are more likely to be accurate a higher weight in the calculation. Every price involved in the calculation is therefore dynamically weighted and the look back period over this ‘OPOS’ EMA is 1hr i.e. 5921 slots.
  3. Minimum number of publishers: Prices on Pyth are aggregated from a number of world class data providers and this parameter provides the minimum number of publishers needed for the price published on chain to be valid. Currently more than 80+ data providers ranging from trading firms, exchanges, and market makers provide data to Pyth.
  4. Valid slot: Pyth along with price data also publishes the valid slot number at which the last successful aggregation of price was published on-chain which must be within 25 slots of last published slot. This helps in protocols to know the liveliness of the published aggregated price.

Apart from the above parameters pyth also publishes minimum number of publishers, last slot, ema confidence read more about it here

Dynamic Pricing Engine

Flash’s liquidity pool as highlighted in our previous blog is the main engine that powers all the trading. Flash liquidity pool as an index quotes all the underlying assets based on oracle price and the pricing function takes multiple parameters into consideration such as slot update, confidence interval, and EMA posted by Pyth as described above.

The dynamic pricing function works by adding a spread to the pricing of an asset when users trade against the pool and this spread is added to replicate the behaviour of market makers during volatile movements e.g quoting wide in times of high volatility and uncertainty of fair value. The spread is derived from Pyth’s confidence interval which is not exactly a function of price movement but defined to get exact price deviation from the median of all price publishers. The spread is only added to the price when there is an significant deviation between spot price and EMA price published by Pyth on-chain hence the spread will only be added when the deviation between spot and ema prices reaches the threshold percentage. This will only happen during significant price movement of underlying assets so traders will have a very tight spread when trading most of the time. This mechanism helps Flash to allow trading of volatile assets at minimal slippage using the liquidity pool and offer up to 100x leverage.

The spread in the context of Flash is essentially a price premium since its added into pricing that is used across spot and perps trading on Flash. To better understand, let’s look at a case study below:

On Jan 2nd, 2023, the price of Solana moved more than 18% in less than 1 minute. Moves like these are really profitable for arbitrageurs but if we incorporate the price premiums to mimic the spread that is generally added by market makers during such movements then the pool will be less affected by toxic flow.

The above example is one of many case studies we internally simulated to better understand the effects of high volatility and overall profitability of the pool. To keep things in line the next deep dive blog will shed more light on how we simulated various scenarios and did one of a kind economic audit to cover various flash crashes, stable-coin depegs, and times when Solana was halted.

At Flash.trade, we are here to revolutionize your trading experience on the most powerful blockchain capable of supporting the most diverse range of DeFi solutions.

Stay updated by following @FlashTrade_ and joining our discord here.