SIP-258: Trade Directionality In Pricing of Atomic Swaps

Author
StatusImplemented
TypeGovernance
NetworkEthereum
ImplementorMEB (@barrasso)
ReleaseTBD
ProposalLoading status...
Created2022-07-05

Simple Summary

The sip improves the pricing of atomic swaps, originally laid out in SIP-120 and recently updated in SIP-198, by incorporating directionality of the trade into the uniswap pricing methodology

Abstract

Update the atomic price methodology as to incorporate directionality of the trade into the uniswap price aggregation method.

Motivation

Currently, the function used to compute an atomic price for sETH and sBTC is the worse between chainlink price and the min(uniswap_twap,uniswap_spot). The intention of the atomic swaps is to offer the worse fill between all 3 price combinations. This would allow the protocol to lower fees to the point where we retain a competitive advantage over other amm exchanges. Updating the ExchangeRatesWithDexPricing incorporates directionality of the trade into the execution and allows Synthetix to offer competitive pricing for longer periods.

Specification

Technical Specification

Update to the atomic price methodology

Context on Pricing and Naming Conventions

The price of an exchange when a trade materializes from a source (SRC) currency to a destination (DEST) currency can be broken down into two price components:

  • The price of the source currency in dollar terms is denoted SRC/USD, for example BTC/USD is at 38k$ per bitcoin.
  • the price of the destination in dollar terms, denoted DEST/USD
  • A trader, trades an amount of SRC currency, called SRC_Amount and he receives DEST_Amount.
  • SRC/DEST is the trade price, being the amount of destination currency received per source currency. It is obtained by dividing SRC/USD by DEST/USD. For example trading 1 bitcoin into eur, with destination EUR/USD 1.05$ and source BTC/USD at 38k$. Applying the previous formula will lead to 38k/1.05 , resulting in 36,190 EUR received, assuming 0 fees.
  • The computation of DEST_Amount is given by SRC_Amount * SRC/DEST * (1- fee).
  • In the case where SRC or DEST is the US Dollar, the same logic still applies, where one of the components is USD/USD or 1. An example of this is a trade of 1 USD into BTC, in such a situation the trade price SRC/DEST is obtained by dividing USD/USD 1 by BTC/USD (38k$) which leads to 0.0000263 btc received.
Computation Methodology in Atomic Pricing Updated

Atomic exchanges leads to combinations that involve the usage of chainlink in certain situations and the usage of uniswap in others or a combination of the two sources of prices. Although, the computation was laid out in SIP-198, it did not specify how would uniswap prices be derived, which resulted in the usage of the min between Uniswap-Spot and UniswapTwap, resulting in few edge case fills that are distant from market prices. The updated computation below clearly specifies how Twap and Spot should be used in order to arrive at the fill price.

  1. PureChainlink Vs Not Pure Chainlink:
  • When a pure chainlink price is assigned to a currency, the chainlink price is used.
  • Otherwise the worse price between chainlink and uniswap-spot and uniswap-twap is used in the combination. Worse price, means the price that would result in the lowest DEST_Amount.
  1. Naming Convention:
  • UniSpot(SRC/USD) and UniSpot(DEST/USD) refers to the price obtained from uniswap V3 spot.
  • UniTwap(SRC/USD) and UniTwap(DEST/USD) refers to the price obtained from uniswap V3 twap.
  • Chainlink(SRC/USD) and Chainlink(DEST/USD) refers to the price obtained from chainlink price feed
  1. Below are the different scenarios that could arise for trading currencies that have or don't have the Pure Chainlink tag:
  • SRC and DEST are both set to trade at the PureChainlinkPrice, in such a case, both Chainlink(SRC/USD) and Chainlink(DEST/USD) are used to compute SRC/DEST by dividing Chainlink(SRC/USD) by Chainlink(DEST/USD).
  • SRC is NOT set to PureChainlinkPrice and DEST is set to PureChainlinkPrice. Therefore, SRC/DEST is obtained by dividing min(UniSpot(SRC/USD),UniTwap(SRC/USD),Chainlink(SRC/USD)) by Chainlink(DEST/USD).
  • SRC is set to PureChainlinkPrice and DEST is NOT set to PureChainlinkPrice. Therefore, SRC/DEST is obtained by dividing Chainlink(SRC/USD) by max(Chainlink(DEST/USD),UniSpot(DEST/USD),UniTwap(DEST/USD)).
  • Both SRC and DEST are NOT set to PureChainlinkPrice, in such a case, SRC/DEST is obtained by dividing min(UniSpot(SRC/USD),UniTwap(SRC/USD),Chainlink(SRC/USD)) by max(Chainlink(DEST/USD),UniSpot(DEST/USD),UniTwap(DEST/USD)).

Test Cases

  • Given that sEUR is set to pure chainlink pricing and sETH and sBTC are not set to pure chainlink pricing
    • Given that a trader trades 10 sBTC to sEUR
      • Given that Chainlink(EUR/USD) is at 1.1$ and Chainlink(BTC/USD) is at 19k$, UniSpot(BTC/USD) is at 20k$ and UniTwap(BTC/USD) is at 21k$
        • When the user attempts to trade, setting the minReturnAmount to 17,195 sEUR
          • ✅ Then it succeeds and the following take place:
            • 17,195 sEUR is sent to the user, computed by min(19k,20k,21k) * 10 / 1.1 * (1-45/1e4)
            • 855 sUSD is sent to the fee pool, computed by 10 * min(19k,20k,21k) * (45/1e4)
        • When the user attempts to trade, setting the minReturnAmount to 17,196 sEUR
          • ❌ Then it reverts, due to the retun amount being too low
      • Given that Chainlink(EUR/USD) is at 1.1$ and Chainlink(BTC/USD) is at 17k$, UniSpot(BTC/USD) is at 16k$ and UniTwap(BTC/USD) is at 18k$
        • When the user attempts to trade, setting the minReturnAmount to 14k sEUR
          • ✅ Then it succeeds and the following take place:
            • 14,480 sEUR is sent to the user, computed by min(16k,17k,18k) * 10 / 1.1 * (1-45/1e4)
            • 720 sUSD is sent to the fee pool, computed by 10 * min(16k,17k,18k) * (45/1e4)
      • Given that Chainlink(EUR/USD) is at 1.1$ and Chainlink(BTC/USD) is at 15k$, UniSpot(BTC/USD) is at 14k$ and UniTwap(BTC/USD) is at 13k$
        • When the user attempts to trade, setting the minReturnAmount to 11k sEUR
          • ✅ Then it succeeds and the following take place:
            • 11,765 sEUR is sent to the user, computed by min(13k,14k,15k) * 10 / 1.1 * (1-45/1e4)
            • 585 sUSD is sent to the fee pool, computed by 10 * min(13k,14k,15k) * (45/1e4)
    • Given that a trader trades 10,000 sEUR to sBTC
      • Given that Chainlink(EUR/USD) is at 1.1$ and Chainlink(BTC/USD) is at 19k$, UniSpot(BTC/USD) is at 20k$ and UniTwap(BTC/USD) is at 21k$
        • When the user attempts to trade, setting the minReturnAmount to 5.214 sBTC
          • ✅ Then it succeeds and the following take place:
            • 5.2145 sBTC is sent to the user, computed by 1.1 / max(19k,20k,21k) * 10e4 * (1-45/1e4)
            • 495 sUSD is sent to the fee pool, computed by 10e4 * 1.1 * (45/1e4)
      • Given that Chainlink(EUR/USD) is at 1.1$ and Chainlink(BTC/USD) is at 19$, UniSpot(BTC/USD) is at 18k$ and UniTwap(BTC/USD) is at 17k$
        • When the user attempts to trade, setting the minReturnAmount to 5.7 sBTC
          • ✅ Then it succeeds and the following take place:
            • 5.7634 sBTC is sent to the user, computed by 1.1 / max(17k,18k,19k) * 10e4 * (1-45/1e4)
            • 495 sUSD is sent to the fee pool, computed by 10e4 * 1.1 * (45/1e4)
      • Given that Chainlink(EUR/USD) is at 1.1$ and Chainlink(BTC/USD) is at 15k$, UniSpot(BTC/USD) is at 17k$ and UniTwap(BTC/USD) is at 16$
        • When the user attempts to trade, setting the minReturnAmount to 6.44 sBTC
          • ✅ Then it succeeds and the following take place:
            • 6.4415 sBTC is sent to the user, computed by 1.1 / max(15k,16k,17k) * 10e4 * (1-45/1e4)
            • 495 sUSD is sent to the fee pool, computed by 10e4 * 1.1 * (45/1e4)

Configurable Values (Via SCCP)

The same configurable values as those set out in SIP-120 and SIP-198.

Copyright and related rights waived via CC0.