{"componentChunkName":"component---src-pages-sips-sip-markdown-remark-frontmatter-sip-tsx","path":"/sips/sip-264/","result":{"data":{"markdownRemark":{"fileAbsolutePath":"/vercel/path0/content/sips/sip-264.md","frontmatter":{"sip":264,"sccp":null,"title":"Update Atomic Pricing","network":"Ethereum","author":"kaleb (@kaleb-keny), Afif (@aband1)","type":"Governance","proposal":null,"implementor":"TBD","release":null,"created":"2022-07-28T00:00:00.000Z","updated":null,"status":"Rejected"},"html":"<!--You can leave these HTML comments in your merged SIP and delete the visible duplicate text guides, they will not appear and may be helpful to refer to if you edit it again. This is the suggested template for new SIPs. Note that an SIP number will be assigned by an editor. When opening a pull request to submit your SIP, please use an abbreviated title in the filename, `sip-draft_title_abbrev.md`. The title should be 44 characters or less.-->\n<h2 id=\"simple-summary\" style=\"position:relative;\"><a href=\"#simple-summary\" aria-label=\"simple summary permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Simple Summary</h2>\n<!--\"If you can't explain it simply, you don't understand it well enough.\" Simply describe the outcome the proposed changes intends to achieve. This should be non-technical and accessible to a casual community member.-->\n<p>This SIP proposes improvements to the atomic pricing methodology incorporating an in-block spot price (i.e. the live price).</p>\n<h2 id=\"abstract\" style=\"position:relative;\"><a href=\"#abstract\" aria-label=\"abstract permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Abstract</h2>\n<!--A short (~200 word) description of the proposed change, the abstract should clearly describe the proposed change. This is what *will* be done if the SIP is implemented, not *why* it should be done or *how* it will be done. If the SIP proposes deploying a new contract, write, \"we propose to deploy a new contract that will do x\".-->\n<p>Update the <a href=\"https://github.com/Synthetixio/SIPs/blob/master/content/sips/sip-258.md#computation-methodology-in-atomic-pricing-updated\">atomic price methodology</a> as to incorporate the in-block live price into the computation of atomic price (specified in the specification below).</p>\n<h2 id=\"motivation\" style=\"position:relative;\"><a href=\"#motivation\" aria-label=\"motivation permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Motivation</h2>\n<!--This is the problem statement. This is the *why* of the SIP. It should clearly explain *why* the current state of the protocol is inadequate.  It is critical that you explain *why* the change is needed, if the SIP proposes changing how something is calculated, you must address *why* the current calculation is innaccurate or wrong. This is not the place to describe how the SIP will address the issue!-->\n<p>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 <a href=\"https://ibb.co/sq4Sw3c\">scatter plot</a>. The scatter plot shows the delta between centralized exchange prices and uniswap prices when considering same block price (orange) versus previous block pricing (blue).\nIt is important to mention that the updated computation would use the worse between live price, price at the previous block, twap and chainlink.</p>\n<p>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 <code>uniswapInputAmount</code>).\n<code>uniswapInputAmount</code> is the amount used as an input to measure the price obtained by trading on uniswap.</p>\n<p>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 <code>minReturn</code> 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.</p>\n<p>The live price usage would add around <a href=\"https://etherscan.io/tx/0x1f0061ac8ad18409b4f5fc2fdf74b03c9e22afebae96ce40fd4d1731ef76b043\">100k units</a> of gas to the transaction per trade.</p>\n<h2 id=\"specification\" style=\"position:relative;\"><a href=\"#specification\" aria-label=\"specification permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Specification</h2>\n<!--The specification should describe the syntax and semantics of any new feature, there are five sections\n1. Overview\n2. Rationale\n3. Technical Specification\n4. Test Cases\n5. Configurable Values\n-->\n<h3 id=\"technical-specification\" style=\"position:relative;\"><a href=\"#technical-specification\" aria-label=\"technical specification permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Technical Specification</h3>\n<!--The technical specification should outline the public API of the changes proposed. That is, changes to any of the interfaces Synthetix currently exposes or the creations of new ones.-->\n<h4 id=\"update-to-the-atomic-price-methodology\" style=\"position:relative;\"><a href=\"#update-to-the-atomic-price-methodology\" aria-label=\"update to the atomic price methodology permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Update to the atomic price methodology</h4>\n<h5 id=\"computation-methodology-in-atomic-pricing-updated\" style=\"position:relative;\"><a href=\"#computation-methodology-in-atomic-pricing-updated\" aria-label=\"computation methodology in atomic pricing updated permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Computation Methodology in Atomic Pricing Updated</h5>\n<p>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 <a href=\"https://sips.synthetix.io/sips/sip-258/\">SIP-258</a>, incorporating a <code>UniLive</code> price which is the in-block price from uniswap.</p>\n<ol>\n<li>PureChainlink Vs Not Pure Chainlink:</li>\n</ol>\n<ul>\n<li>When a pure chainlink price is assigned to a currency, the chainlink price is used.</li>\n<li>Otherwise the <strong>worse</strong> 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 <code>DEST_Amount</code>.</li>\n</ul>\n<ol start=\"2\">\n<li>Naming Convention:</li>\n</ol>\n<ul>\n<li>\n<p><code>UniLive(SRC/USD)</code> and <code>UniLive(DEST/USD)</code> 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:</p>\n<p>a) As implemented in <a href=\"https://sips.synthetix.io/sips/sip-120/\">SIP-120</a>, in case the 5 bp pool is specified, the implementation should determine the price of the <code>synthEquivalent/wETH</code> price by hoping over the <code>wETH/synthEquivalent</code> &#x26; <code>wETH/USDC</code> uniswap pools in case no native <code>synthEquivalent/USDC</code> exists. Therefore the implementation will need to hop over the  <a href=\"https://etherscan.io/address/0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640\">wETH/USDC</a> and <a href=\"https://etherscan.io/address/0x4585FE77225b41b697C938B018E2Ac67Ac5a20c0\">wBTC/wETH</a> pools in order to arrive at the price of wBTC on the 5 bp pool.</p>\n<p>b) In order to arrive at the live uniswap price <a href=\"https://docs.uniswap.org/protocol/reference/periphery/interfaces/IQuoterV2#quoteexactinput\">quoteExactInput</a> function could be utilized on chain, despite these function not being gas efficient. The live price is the rate obtained by converting a <code>uniswapInputAmount</code> worth of the <code>inputCurrency</code> into the <code>outputCurrency</code>. Hence, a user that swaps <code>sUSD</code> to <code>sBTC</code>, the live price (excluding fees) is the computed by <code>outputAmount</code> / [<code>inputAmount</code> * (1-<code>uniswapFee</code>)]</p>\n<pre><code>  - `inputAmount` is specified via sccp and allows us to incorporate a form slippage into the fill amount.\n  - `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.\n</code></pre>\n</li>\n<li>\n<p><code>UniSpot(SRC/USD)</code> and <code>UniSpot(DEST/USD)</code> refers to the price obtained from uniswap V3 spot in the previous block.</p>\n</li>\n<li>\n<p><code>UniTwap(SRC/USD)</code> and <code>UniTwap(DEST/USD)</code> refers to the price obtained from uniswap V3 twap.</p>\n</li>\n<li>\n<p><code>Chainlink(SRC/USD)</code> and <code>Chainlink(DEST/USD)</code> refers to the price obtained from chainlink price feed</p>\n</li>\n</ul>\n<ol start=\"3\">\n<li>Below are the different scenarios that could arise for trading currencies that have or don't have the Pure Chainlink tag:</li>\n</ol>\n<ul>\n<li><code>SRC</code> and <code>DEST</code> are both set to trade at the PureChainlinkPrice, in such a case, both <code>Chainlink(SRC/USD)</code> and <code>Chainlink(DEST/USD)</code> are used to compute <code>SRC/DEST</code> by dividing <code>Chainlink(SRC/USD)</code> by <code>Chainlink(DEST/USD)</code>.</li>\n<li><code>SRC</code> is <strong>NOT</strong> set to PureChainlinkPrice and <code>DEST</code> is set to PureChainlinkPrice. Therefore, <code>SRC/DEST</code> is obtained by dividing min(<code>UniSpot(SRC/USD)</code>,<code>UniLive(SRC/USD)</code>,<code>UniTwap(SRC/USD)</code>,<code>Chainlink(SRC/USD)</code>) by <code>Chainlink(DEST/USD)</code>.</li>\n<li><code>SRC</code> is set to PureChainlinkPrice and <code>DEST</code> is <strong>NOT</strong> set to PureChainlinkPrice. Therefore, <code>SRC/DEST</code> is obtained by dividing <code>Chainlink(SRC/USD)</code> by max(<code>Chainlink(DEST/USD)</code>,<code>UniLive(DEST/USD)</code>,<code>UniSpot(DEST/USD)</code>,<code>UniTwap(DEST/USD)</code>).</li>\n<li>Both <code>SRC</code> and <code>DEST</code> are <strong>NOT</strong> set to PureChainlinkPrice, in such a case, <code>SRC/DEST</code> is obtained by dividing min(<code>UniSpot(SRC/USD)</code>,<code>UniLive(SRC/USD)</code>,<code>UniTwap(SRC/USD)</code>,<code>Chainlink(SRC/USD)</code>) by max(<code>Chainlink(DEST/USD)</code>,<code>UniLive(DEST/USD)</code>,<code>UniSpot(DEST/USD)</code>,<code>UniTwap(DEST/USD)</code>).</li>\n</ul>\n<h3 id=\"test-cases\" style=\"position:relative;\"><a href=\"#test-cases\" aria-label=\"test cases permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Test Cases</h3>\n<!--Test cases for an implementation are mandatory for SIPs but can be included with the implementation..-->\n<h3 id=\"configurable-values-via-sccp\" style=\"position:relative;\"><a href=\"#configurable-values-via-sccp\" aria-label=\"configurable values via sccp permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Configurable Values (Via SCCP)</h3>\n<!--Please list all values configurable via SCCP under this implementation.-->\n<p>The same configurable values as those set out in <a href=\"https://sips.synthetix.io/sips/sip-120/\">SIP-120</a>,  <a href=\"https://sips.synthetix.io/sips/sip-198/\">SIP-198</a> and <a href=\"https://sips.synthetix.io/sips/sip-258/\">SIP-258</a>.\nuniswap.</p>\n<p><code>uniswapInputAmount</code> is an amount that should be specified per <code>atomicEquivalent</code> that allows for the calculation of the live uniswap price.\nIn case <code>uniswapInputAmount</code> is not specified on the <code>atomicEquivalent</code> 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).</p>\n<p>Rejected by author</p>\n<h2 id=\"copyright\" style=\"position:relative;\"><a href=\"#copyright\" aria-label=\"copyright permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Copyright</h2>\n<p>Copyright and related rights waived via <a href=\"https://creativecommons.org/publicdomain/zero/1.0/\">CC0</a>.</p>"}},"pageContext":{"id":"6748da92-bef2-56c5-b55a-ef5f6518d95a","frontmatter__sip":264,"__params":{"frontmatter__sip":"264"}}},"staticQueryHashes":[]}