SIP-258: Trade Directionality In Pricing of Atomic Swaps
Author | |
---|---|
Status | Implemented |
Type | Governance |
Network | Ethereum |
Implementor | MEB (@barrasso) |
Release | TBD |
Proposal | Loading status... |
Created | 2022-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 exampleBTC/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, calledSRC_Amount
and he receivesDEST_Amount
. SRC/DEST
is the trade price, being the amount of destination currency received per source currency. It is obtained by dividingSRC/USD
byDEST/USD
. For example trading 1 bitcoin into eur, with destinationEUR/USD
1.05$ and sourceBTC/USD
at 38k$. Applying the previous formula will lead to38k/1.05
, resulting in 36,190 EUR received, assuming 0 fees.- The computation of
DEST_Amount
is given bySRC_Amount * SRC/DEST * (1- fee)
. - In the case where
SRC
orDEST
is the US Dollar, the same logic still applies, where one of the components isUSD/USD
or 1. An example of this is a trade of 1 USD into BTC, in such a situation the trade priceSRC/DEST
is obtained by dividingUSD/USD
1 byBTC/USD
(38k$) which leads to0.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.
- 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
.
- Naming Convention:
UniSpot(SRC/USD)
andUniSpot(DEST/USD)
refers to the price obtained from uniswap V3 spot.UniTwap(SRC/USD)
andUniTwap(DEST/USD)
refers to the price obtained from uniswap V3 twap.Chainlink(SRC/USD)
andChainlink(DEST/USD)
refers to the price obtained from chainlink price feed
- Below are the different scenarios that could arise for trading currencies that have or don't have the Pure Chainlink tag:
SRC
andDEST
are both set to trade at the PureChainlinkPrice, in such a case, bothChainlink(SRC/USD)
andChainlink(DEST/USD)
are used to computeSRC/DEST
by dividingChainlink(SRC/USD)
byChainlink(DEST/USD)
.SRC
is NOT set to PureChainlinkPrice andDEST
is set to PureChainlinkPrice. Therefore,SRC/DEST
is obtained by dividing min(UniSpot(SRC/USD)
,UniTwap(SRC/USD)
,Chainlink(SRC/USD)
) byChainlink(DEST/USD)
.SRC
is set to PureChainlinkPrice andDEST
is NOT set to PureChainlinkPrice. Therefore,SRC/DEST
is obtained by dividingChainlink(SRC/USD)
by max(Chainlink(DEST/USD)
,UniSpot(DEST/USD)
,UniTwap(DEST/USD)
).- Both
SRC
andDEST
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$ andChainlink(BTC/USD)
is at 19k$,UniSpot(BTC/USD)
is at 20k$ andUniTwap(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)
- ✅ Then it succeeds and the following take place:
- When the user attempts to trade, setting the minReturnAmount to 17,196 sEUR
- ❌ Then it reverts, due to the retun amount being too low
- When the user attempts to trade, setting the minReturnAmount to 17,195 sEUR
- Given that
Chainlink(EUR/USD)
is at 1.1$ andChainlink(BTC/USD)
is at 17k$,UniSpot(BTC/USD)
is at 16k$ andUniTwap(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)
- ✅ Then it succeeds and the following take place:
- When the user attempts to trade, setting the minReturnAmount to 14k sEUR
- Given that
Chainlink(EUR/USD)
is at 1.1$ andChainlink(BTC/USD)
is at 15k$,UniSpot(BTC/USD)
is at 14k$ andUniTwap(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)
- ✅ Then it succeeds and the following take place:
- When the user attempts to trade, setting the minReturnAmount to 11k sEUR
- Given that
- Given that a trader trades 10,000 sEUR to sBTC
- Given that
Chainlink(EUR/USD)
is at 1.1$ andChainlink(BTC/USD)
is at 19k$,UniSpot(BTC/USD)
is at 20k$ andUniTwap(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)
- ✅ Then it succeeds and the following take place:
- When the user attempts to trade, setting the minReturnAmount to 5.214 sBTC
- Given that
Chainlink(EUR/USD)
is at 1.1$ andChainlink(BTC/USD)
is at 19$,UniSpot(BTC/USD)
is at 18k$ andUniTwap(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)
- ✅ Then it succeeds and the following take place:
- When the user attempts to trade, setting the minReturnAmount to 5.7 sBTC
- Given that
Chainlink(EUR/USD)
is at 1.1$ andChainlink(BTC/USD)
is at 15k$,UniSpot(BTC/USD)
is at 17k$ andUniTwap(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)
- ✅ Then it succeeds and the following take place:
- When the user attempts to trade, setting the minReturnAmount to 6.44 sBTC
- Given that
- Given that a trader trades 10 sBTC to sEUR
Configurable Values (Via SCCP)
The same configurable values as those set out in SIP-120 and SIP-198.
Copyright
Copyright and related rights waived via CC0.