This SIP proposes improvements to the atomic pricing methodology incorporating an in-block spot price (i.e. the live price).
Update the atomic price methodology as to incorporate the in-block live price into the computation of atomic price (specified in the specification below).
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 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.
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
- Naming Convention:
UniLive(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/wETHprice by hoping over the
wETH/USDCuniswap pools in case no native
synthEquivalent/USDCexists. 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
uniswapInputAmountworth of the
outputCurrency. Hence, a user that swaps
sBTC, the live price (excluding fees) is the computed by
- `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(DEST/USD)refers to the price obtained from uniswap V3 spot in the previous block.
UniTwap(DEST/USD)refers to the price obtained from uniswap V3 twap.
Chainlink(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:
DESTare both set to trade at the PureChainlinkPrice, in such a case, both
Chainlink(DEST/USD)are used to compute
SRCis NOT set to PureChainlinkPrice and
DESTis set to PureChainlinkPrice. Therefore,
SRC/DESTis obtained by dividing min(
SRCis set to PureChainlinkPrice and
DESTis NOT set to PureChainlinkPrice. Therefore,
SRC/DESTis obtained by dividing
DESTare NOT set to PureChainlinkPrice, in such a case,
SRC/DESTis obtained by dividing min(
Chainlink(SRC/USD)) by max(
uniswapInputAmount is an amount that should be specified per
atomicEquivalent that allows for the calculation of the live uniswap price.
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 and related rights waived via CC0.