SIP-264: Update Atomic Pricing
Author | |
---|---|
Status | Rejected |
Type | Governance |
Network | Ethereum |
Implementor | TBD |
Release | TBD |
Created | 2022-07-28 |
Simple Summary
This SIP proposes improvements to the atomic pricing methodology incorporating an in-block spot price (i.e. the live price).
Abstract
Update the atomic price methodology as to incorporate the in-block live price into the computation of atomic price (specified in the specification below).
Motivation
The current implementation of atomic swaps uses the spot price at the previous block. This exposes the debt pool to latency attacks, as the spot price at the previous block does not incorporate the latest updated information. Hence using the live spot helps reduce the latency considerably as shown in the scatter plot. The scatter plot shows the delta between centralized exchange prices and uniswap prices when considering same block price (orange) versus previous block pricing (blue). It is important to mention that the updated computation would use the worse between live price, price at the previous block, twap and chainlink.
Latency arbitrageurs can still push their transactions at the head of the block via flashbots or high gas prices, as to front-run a uniswap pool arbitrage and updated oracle pricing. The protocol would need to lean against this by increasing fees and incorporating slippage (using uniswapInputAmount
).
uniswapInputAmount
is the amount used as an input to measure the price obtained by trading on uniswap.
It is also worth pointing out out that this does expose the protocol to the ability of arbitrageurs to manipulate the uniswap price as to sandwish users or take advantage of latency. Therefore the minReturn
is necessary to protect users and fees need to be high enough as lean against such oracle manipulation, the damage however is constrained to the use of the worse price with previous block price, twap and chainlink.
The live price usage would add around 100k units of gas to the transaction per trade.
Specification
Technical Specification
Update to the atomic price methodology
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. This sip updates the computation laid out in SIP-258, incorporating a UniLive
price which is the in-block price from uniswap.
- 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:
-
UniLive(SRC/USD)
andUniLive(DEST/USD)
refers to the price obtained from uniswap V3 spot in the current block, reflecting arbitrages on uniswap pool that had taken place within the same block. Few implementation details:a) As implemented in SIP-120, in case the 5 bp pool is specified, the implementation should determine the price of the
synthEquivalent/wETH
price by hoping over thewETH/synthEquivalent
&wETH/USDC
uniswap pools in case no nativesynthEquivalent/USDC
exists. Therefore the implementation will need to hop over the wETH/USDC and wBTC/wETH pools in order to arrive at the price of wBTC on the 5 bp pool.b) In order to arrive at the live uniswap price quoteExactInput function could be utilized on chain, despite these function not being gas efficient. The live price is the rate obtained by converting a
uniswapInputAmount
worth of theinputCurrency
into theoutputCurrency
. Hence, a user that swapssUSD
tosBTC
, the live price (excluding fees) is the computed byoutputAmount
/ [inputAmount
* (1-uniswapFee
)]- `inputAmount` is specified via sccp and allows us to incorporate a form slippage into the fill amount. - `uniswapFee` is dependent on the specified pool being used, we'll assume for the sake of simplification that uniswap admin fees will remain at zero.
-
UniSpot(SRC/USD)
andUniSpot(DEST/USD)
refers to the price obtained from uniswap V3 spot in the previous block. -
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)
,UniLive(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)
,UniLive(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)
,UniLive(SRC/USD)
,UniTwap(SRC/USD)
,Chainlink(SRC/USD)
) by max(Chainlink(DEST/USD)
,UniLive(DEST/USD)
,UniSpot(DEST/USD)
,UniTwap(DEST/USD)
).
Test Cases
Configurable Values (Via SCCP)
The same configurable values as those set out in SIP-120, SIP-198 and SIP-258. uniswap.
uniswapInputAmount
is an amount that should be specified per atomicEquivalent
that allows for the calculation of the live uniswap price.
In case uniswapInputAmount
is not specified on the atomicEquivalent
being traded, then the amount being traded is used to fetch the uniswap live price (i.e. using the same amount of slippage one would obtain by trading on uniswap).
Rejected by author
Copyright
Copyright and related rights waived via CC0.