Swaps
Last updated
Last updated
Dyson is built as a collection of proactive market makers (PMMs), where each pool has access to the price and liquidity information from all other pools, as well as oracle prices (if available).
Before a swap occurs, a global midpoint price for each token is established based on pricing and liquidity from overlapping pools. For example, for a swap in a SOL-ETH pool, all of the SOL-X pools and all of the ETH-X pools are scanned. The most recent prices for tokens X are used for translation into USD.
Each PMM also has its own internal mark price based on token holdings and swap history. Only swaps which push the pool's mark price away from the global midpoint are allowed as-is (i.e. any swap offering a worse-than-midpoint price). Any swap pushing the pool's mark price towards the global midpoint (i.e. any swap attempting to trade at a better price than the global midpoint) will instead begin at the global midpoint. Trades assigned to start at the global midpoint still affect the internal mark price, based on the number of tokens swapped. In some ways this is similar to introducing a spread during times of price uncertainty or high volatility.
The mechanism above helps to avoid transacting at undesirable prices, even without an oracle. It is not entirely immune to arbitrage though, for example: if all of the SOL-X pools approximately agree on a price for SOL, and the external price (on centralized exchanges) changes dramatically in between blocks, then a portion of the pools may get arb'ed before the midpoint moves away from the outdated price. Still, a significant portion of IL is avoided with this one mechanism.
If oracle prices are available for tokens in a pool, then those prices will be used to establish the midpoint. If pricing is only available for one token in a pool, then the oracle price will be used for that token and the process above will determine pricing for the other token.
Since swaps occur at the worst price of: [midpoint or oracle price] and [internal PMM mark price], oracle mis-pricing or stale oracle feeds are not a concern for liquidity providers. In this case the pool will simply offer uncompetitive pricing. If there is no oracle feed and there are no overlapping token pools to establish a midpoint, then in the worst case scenario the pool will behave similarly to a traditional pool. However, all-to-all token pools will be created to ensure overlapping pools (with additional price information) and to capture all possible arbitrage profits (more on this below).
The swap process is designed to avoid transacting at undesirable prices, by temporarily moving the pool price to the global midpoint price when a pool is offering better-than-market prices. However, to capture path-dependent arbitrage opportunities, we need a way to bring all prices back in sync; that they may again disperse.