{"componentChunkName":"component---src-pages-sips-sip-markdown-remark-frontmatter-sip-tsx","path":"/sips/sip-272/","result":{"data":{"markdownRemark":{"fileAbsolutePath":"/vercel/path0/content/sips/sip-272.md","frontmatter":{"sip":272,"sccp":null,"title":"Atomic Swaps - Dynamic Fees","network":"Ethereum","author":"Kaleb (@kaleb-keny), Afif (@aband1)","type":"Governance","proposal":"https://snapshot.org/#/snxgov.eth/proposal/0xb568495c135b4d85bb49260245a53570bfabce82ccb095eb7ed9fe486bd7e3f7","implementor":"TBD","release":null,"created":"2022-08-17T00: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 to incorporate dynamic fees into the atomic swap methodology.</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>The dynamic fee model can be calibrated to fit the slippage function of any designated order book, hence higher fees would be levied as per the directional flow of the trade, resulting in more compensation to snx stakers when they take on larger positions. The calibrated dynamic model takes the following form:</p>\n<p>$$\nG(x,y) =  2 \\frac {\\frac{2}{3} u_0 (|x| ^ {3/2} - |y|^ {3/2} ) + \\frac{1}{2} u_1 (|x|^2 - |y|^2)}{|x| - |y|}\n$$</p>\n<ul>\n<li>cumulative trade volume in USD is updated at each interaction, where trades into synth increase <code>cumulativeVolume</code> and out of synth lowers the amount</li>\n<li>$x$ is the post-trade and $y$ the pre-trade cumulative volume in USD</li>\n<li>In case cumulative volume flips signs, due to a significant trade in the opposing direction, then $G(x,0)$ is used to compute the fee</li>\n<li>All trades will have to route through <code>sUSD</code></li>\n<li>The frequency by which <code>cumulativeVolume</code> resets is configurable via SCCP, denoted <code>atomicKBlocks</code></li>\n<li>$u_{0}$ and $u_{1}$  are calibrated off-chain for each synth, as shown in this <a href=\"https://github.com/kaleb-keny/synthetix_slippage_calibration_sip_272\">repo</a></li>\n</ul>\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 Synthetix protocol spot trading product is an attempt at being a market maker that offers trading through the use of an oracle reading. This is different from the approach offered by most other AMMs, which in contrast use the composition of liquidity pools in order to gauge a price and subsequently incorporate slippage into the trade in order to compensate LPs.</p>\n<p>The usage of oracle sources to execute a fill results in the Synthetix protocol being a constant target of latency arbitrage aimed at picking off advantageous pricing. To compensate, fees have been increased to a point at which the product itself failing at its mission of offering a venue for cheap spot trading. Though latency is as much of a problem for amm's as it is for Synthetix, the difference lies in AMM fees from small random trades which more make up for the capital losses incurred by price adjustments; as well as the slippage incorporated ensuring these lp price adjustments are efficient.</p>\n<p>From Synthetix's perspective, attempts at this tackling this problem have sought to maintain a no slippage policy at the protocol level. The <a href=\"https://sips.synthetix.io/sips/sip-37/\">Fee reclamation mechanism</a> tackles the latency issue but breaks composability and is unattractive due to the extreme uncertainty on price execution that it causes. The second iteration was the original atomic mechanism, which uses uni-v3 as an additional lively oracle source. Although uniswap is a very effective low-latency oracle source, it still suffers from the impact of a 1 block delay. This opens up a small gap for oracle front-running. Hence, this sips aims at addressing this issue while giving the protocol ability to fine tune execution based on the volatility of the synth.</p>\n<h3 id=\"function-derivation\" style=\"position:relative;\"><a href=\"#function-derivation\" aria-label=\"function derivation 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>Function Derivation</h3>\n<p>The function that would be used to fit an order book curve takes the following form:</p>\n<p>$$\nf(x) = u_0 \\sqrt x + u_1 x\n$$</p>\n<p>However, given the necessity to ensure that the curve is size of volume flow invariant, then the integral, F(x) is used. F(x) represents the area under the slippage curve and is not affected by the size of an individual trade. Hence the weighted average fee can be computed with, <code>F(x)/x</code> for executing a trade when cumulative volume goes from <code>0</code> to <code>x</code>. However to make the outputted numbers quasi-equivalent to those obtained via <code>f(x)</code>, <code>2F(x)/x</code> is used as the base function for querying dynamic fees.\nDeriving the fee that pushes cumulative volume from <code>y</code> to <code>x</code> is then obtained with the function <code>G(x,y)</code> found under the <a href=\"https://sips.synthetix.io/sips/sip-272/#abstract\">abstract</a> section which is a simple transformation of <code>F(x)/x</code>.</p>\n<h3 id=\"proof-of-concept\" style=\"position:relative;\"><a href=\"#proof-of-concept\" aria-label=\"proof of concept 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>Proof Of Concept</h3>\n<p>In order to showcase the model's ability to replicate order books of any form this <a href=\"https://github.com/kaleb-keny/synthetix_slippage_calibration_sip_272/blob/main/output/slippage.jpeg\">figure</a> is used, where we show the slippage incurred when executing orders of different sizes in different markets:</p>\n<ul>\n<li>The x axis represents the market order amount in dollar millions</li>\n<li>The y axis is the slippage in bp for different order book and models of order books, calculated by computing the delta between best prevailing spot price and the average price expected from executing an order of a certain magnitude (shown in the x-axis).</li>\n<li>The <code>uni 5bp</code> line is the slippage incurred when trading on the Uniswap 5 bp ETH/USDC pool</li>\n<li>The <code>cex</code> is the slippage incurred from trading on the binance ETH/USDT orderbook.</li>\n<li>The dashed lines, represent the modeled curves, fitted based on the <code>uni-5bp</code> and <code>cex</code> order books data.</li>\n</ul>\n<p>The proposed model can replicate any order book to a certain degree of precision with the help of the least squares optimization algorithm, an implementation demonstrating this capability is available in this <a href=\"https://github.com/kaleb-keny/synthetix_slippage_calibration_sip_272\">repository</a>.\nIt is important to mention that a no slippage policy can be still configured into a specific synth, simply by setting the functional parameters (<code>u0</code>, <code>u1</code>) to zero.</p>\n<p>The table below displays the slippage incurred when trading on the <code>uniswap-5bp</code> pool and on the binance <code>ETH/USDT</code> pool and the dynamic fees executed with the calibrated models that replicate those order books:</p>\n<table>\n<thead>\n<tr>\n<th><strong>Trade</strong></th>\n<th><strong>uni</strong></th>\n<th><strong>uni_model</strong></th>\n<th><strong>cex</strong></th>\n<th><strong>cex_model</strong></th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><strong>$25,000</strong></td>\n<td>0.00</td>\n<td>0.33</td>\n<td>0.00</td>\n<td>0.27</td>\n</tr>\n<tr>\n<td><strong>$525,000</strong></td>\n<td>6.72</td>\n<td>6.89</td>\n<td>4.39</td>\n<td>5.40</td>\n</tr>\n<tr>\n<td><strong>$1,025,000</strong></td>\n<td>13.44</td>\n<td>13.51</td>\n<td>8.14</td>\n<td>10.20</td>\n</tr>\n<tr>\n<td><strong>$1,525,000</strong></td>\n<td>20.21</td>\n<td>20.18</td>\n<td>12.77</td>\n<td>14.67</td>\n</tr>\n<tr>\n<td><strong>$2,025,000</strong></td>\n<td>27.03</td>\n<td>26.89</td>\n<td>17.63</td>\n<td>18.81</td>\n</tr>\n<tr>\n<td><strong>$2,525,000</strong></td>\n<td>33.90</td>\n<td>33.66</td>\n<td>17.63</td>\n<td>22.62</td>\n</tr>\n<tr>\n<td><strong>$3,025,000</strong></td>\n<td>40.81</td>\n<td>40.47</td>\n<td>24.68</td>\n<td>26.11</td>\n</tr>\n<tr>\n<td><strong>$3,525,000</strong></td>\n<td>47.79</td>\n<td>47.34</td>\n<td>26.94</td>\n<td>29.26</td>\n</tr>\n<tr>\n<td><strong>$4,025,000</strong></td>\n<td>54.85</td>\n<td>54.25</td>\n<td>26.94</td>\n<td>32.08</td>\n</tr>\n<tr>\n<td><strong>$4,525,000</strong></td>\n<td>61.99</td>\n<td>61.22</td>\n<td>26.94</td>\n<td>34.58</td>\n</tr>\n<tr>\n<td><strong>$5,000,000</strong></td>\n<td>68.83</td>\n<td>67.88</td>\n<td>26.94</td>\n<td>36.64</td>\n</tr>\n</tbody>\n</table>\n<p>A interactive copy of the slippage expected with the uni parameters can be found in <a href=\"https://docs.google.com/spreadsheets/d/15EKaVabMfnr_u7XsnetAmAjPFLakPRS_SWU70PEo9eA/copy\">this link</a></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 therefore specification should describe the syntax and semantics of new feature, there are five sections\n1. Overview\n2. Rationale\n3. Technical Specification\n4. Test Cases\n5. Configurable Values\n-->\n<p>The specification includes the following fundamental sections:</p>\n<ul>\n<li>Dynamic Fee Computation Workflow</li>\n<li>Cumulative Volume Structure</li>\n<li>Pricing Methodology</li>\n<li>Functional Parameter Structure</li>\n<li>Dynamic Fee Bounds</li>\n</ul>\n<h3 id=\"dynamic-fee-computation-workflow\" style=\"position:relative;\"><a href=\"#dynamic-fee-computation-workflow\" aria-label=\"dynamic fee computation workflow 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>Dynamic Fee Computation Workflow</h3>\n<p>The dynamic fee computation can be found in this <a href=\"https://ibb.co/xLB6RDJ\">workflow</a>:</p>\n<ol>\n<li>block number delta refers to the delta between the current on-chain blocknumber and the one saved in the <code>cumulativeVolume</code> structure for the synth being traded into or out of</li>\n<li><code>x</code>, <code>y</code> and the function <code>G(x,y)</code> are the variables referred to in the Abstract section</li>\n</ol>\n<h3 id=\"cumulative-volume-structure\" style=\"position:relative;\"><a href=\"#cumulative-volume-structure\" aria-label=\"cumulative volume structure 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>Cumulative Volume Structure</h3>\n<p><code>cumulativeVolume</code> is a nested structure that takes the following form:</p>\n<pre><code>{currencyKey: \n  {'blockNumber': blockNumber,\n   'cumulativeVolume':cumulativeVolume}}\n</code></pre>\n<p>Each time someone trades a synth, volume traded in <code>USD</code> terms is computed using the price obtained with the <code>atomicPrice</code> methodology denoted in <a href=\"https://sips.synthetix.io/sips/sip-258/\">SIP-158</a>. Note that usage of the price incorporating directionality of the source currencyKey being sUSD and destination currencyKey the synth being traded into is preferable.\nThe following logic is then applied when updating the structure:</p>\n<ul>\n<li>In situations in which more than <code>atomicKBlocks</code> blocks have passed since the last time the structure is updated, then the <code>cumulativeVolume</code> is first reset to zero for that synth, before being updated with the latest volume being traded.</li>\n<li>otherwise, the <code>cumulativeVolume</code> is updated cumulatively for the <code>synth</code> being traded into or out from. In case the direction of the trade is into a synth from <code>sUSD</code> the number incorporated into structure is a positive number, otherwise it's a negative number. Hence trades within the same <code>atomicKBlocks</code> blocks in different direction cancel out the the dynamic fee applied.</li>\n</ul>\n<h3 id=\"functional-parameters\" style=\"position:relative;\"><a href=\"#functional-parameters\" aria-label=\"functional parameters 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>Functional Parameters</h3>\n<p><code>functionalParameters</code> is a nested structure that takes the following form:</p>\n<pre><code>{currencyKey: \n  {'u0': u0,\n   'u1': u1}}\n</code></pre>\n<p>The parameters are saved in a structure and configurable via SCCP per <code>currencyKey</code></p>\n<h3 id=\"pricing-methodology\" style=\"position:relative;\"><a href=\"#pricing-methodology\" aria-label=\"pricing 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>Pricing Methodology</h3>\n<p>The exchange would take place with the following computation, assuming a <code>cumulativeVolume</code>  y, having the same sign as x and a price <code>P</code> of the synth in USD terms:</p>\n<ul>\n<li>if the sourceCurrencyKey is <code>sUSD</code>:</li>\n</ul>\n<p>$$<br>\nSrcAmount * \\frac{1}{P} * [1 - baseFee - G(x,y)]  => DestAmount\n$$</p>\n<ul>\n<li>Otherwise:</li>\n</ul>\n<p>$$\nSrcAmount * P * [1- baseFee - G(x,y)]  => DestAmount\n$$</p>\n<h3 id=\"dynamic-fee-bounds\" style=\"position:relative;\"><a href=\"#dynamic-fee-bounds\" aria-label=\"dynamic fee bounds 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>Dynamic Fee Bounds</h3>\n<p>Dynamic fee are bounded between 0 and a variable specified via SCCP, denoted <code>maxAtomicDynamicFee</code></p>\n<h3 id=\"fee-pool-distribution\" style=\"position:relative;\"><a href=\"#fee-pool-distribution\" aria-label=\"fee pool distribution 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>Fee Pool Distribution</h3>\n<p>The dynamic fee will be sent to the fee pool (or burned depending on the implementation of <a href=\"https://sips.synthetix.io/sips/sip-255/\">SIP-255</a>) upon every atomic exchange. Hence, the fee pool should receive <code>SourceAmount*Price*(baseFee + dynamicFee)</code>  upon execution of a trade.</p>\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<p>Pending SC engineers input.</p>\n<p>This SIP has been rejected by the author.</p>\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<h4 id=\"system-configurations\" style=\"position:relative;\"><a href=\"#system-configurations\" aria-label=\"system configurations 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>System Configurations:</h4>\n<ul>\n<li><code>kBlocks</code>: 1</li>\n<li>Current <code>cumulativeVolume</code> structure:</li>\n</ul>\n<pre><code>{'sETH':\n        {'blockNumber': 10,\n        'cumulativeVolume':0}}\n</code></pre>\n<ul>\n<li><code>functionalParameters</code> structure as calibrated here for <a href=\"https://github.com/kaleb-keny/synthetix_slippage_calibration_sip_272/blob/main/output/model.json\"><code>uni_slippage</code></a>:</li>\n</ul>\n<pre><code>{'sETH': \n  {'u0': -1.314892e-03,\n   'u1': +1.434469e-05}}\n</code></pre>\n<ul>\n<li>\n<p>atomic baseFee set to 0</p>\n</li>\n<li>\n<p>G(x,y) can be simulated with the help of this <a href=\"https://docs.google.com/spreadsheets/d/15EKaVabMfnr_u7XsnetAmAjPFLakPRS_SWU70PEo9eA/copy\">spread sheet</a>.</p>\n</li>\n</ul>\n<h4 id=\"trade-example-1\" style=\"position:relative;\"><a href=\"#trade-example-1\" aria-label=\"trade example 1 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>Trade Example 1:</h4>\n<ul>\n<li>\n<p>At blockNumber 10, Swap 1m sUSD to sETH with atomic price at 1,600$ per ETH</p>\n<ol>\n<li>\n<p>Is block number delta (i.e. 0) larger than kBlocks >> False</p>\n</li>\n<li>\n<p>Set</p>\n<p>a) y = 0</p>\n<p>b) x = 1m$</p>\n</li>\n<li>\n<p>Is Sign of x (1m$) is different from sign of y (0) >> True</p>\n</li>\n<li>\n<p>Compute dynamic Fee as G(1m,0):</p>\n</li>\n</ol>\n<p>$$\nG(1m,0) =  2 \\frac {\\frac{2}{3} * (-1.314892 * 10^{-3}) * (|1m| ^ {3/2} - |0|^ {3/2} ) + \\frac{1}{2} * (1.434469 * 10^{-5}) * (|1m|^2 - |0|^2)}{|1m| - |0|} => 12.59 bp\n$$</p>\n<ol start=\"5\">\n<li>Send user 1m / 1600 * (1-12.59 bp) = 624.21 sETH</li>\n</ol>\n</li>\n<li>\n<p>At blockNumber 11, Swap 624.21 sETH to sUSD with atomic price at 1,600$ per ETH</p>\n<ol>\n<li>\n<p>Is block number delta larger than kBlocks >> True</p>\n</li>\n<li>\n<p>Set</p>\n<p>a) y = 0 (reset)</p>\n<p>b) x = - 624.21 sETH * 1600 = - 998,736$</p>\n<p>c) update latest blocknumber to 11</p>\n</li>\n<li>\n<p>Is Sign of x (- 998,736$) is different from sign of y (0) >> True</p>\n</li>\n<li>\n<p>Compute dynamic Fee as G(-998,736,0): 12.59 bp</p>\n</li>\n<li>\n<p>Send user 624.21 * 1600 * (1-12.59 bp) = 997,479 sUSD</p>\n</li>\n</ol>\n</li>\n</ul>\n<h4 id=\"trade-example-2\" style=\"position:relative;\"><a href=\"#trade-example-2\" aria-label=\"trade example 2 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>Trade Example 2:</h4>\n<ul>\n<li>\n<p>At blockNumber 10, Swap 100k sUSD to sETH with atomic price at 1,600$ per ETH</p>\n<ol>\n<li>\n<p>Is block number delta larger than kBlocks >> False</p>\n</li>\n<li>\n<p>Set</p>\n<p>a) y = 0</p>\n<p>b) x = 100k$</p>\n</li>\n<li>\n<p>Is Sign of x (100k$) is different from sign of y (0) >> True</p>\n</li>\n<li>\n<p>Compute dynamic Fee as G(100k,0): 0.88 bp</p>\n</li>\n<li>\n<p>Send user 100k / 1600 * (1-0.88 bp) = 62.494 sETH</p>\n</li>\n</ol>\n</li>\n<li>\n<p>At blockNumber 10, Swap 30 sETH with atomic price at 1,600$ per ETH</p>\n<ol>\n<li>\n<p>Is block number delta larger than kBlocks >> False</p>\n</li>\n<li>\n<p>Set</p>\n<p>a) y =  100k$</p>\n<p>b) x = 100k$ - 30 * 1600 = 52k$</p>\n</li>\n<li>\n<p>Is Sign of x (52k$) is different from sign of y (100k$) >> False</p>\n</li>\n<li>\n<p>Compute dynamic Fee as G(52k$,100k$): 2.63 bp</p>\n</li>\n<li>\n<p>Send user 30 * 1600 * (1-2.63 bp) = 47,987 sUSD</p>\n</li>\n</ol>\n</li>\n<li>\n<p>At blockNumber 10, Swap 40 sETH with atomic price at 1,600$ per ETH</p>\n<ol>\n<li>\n<p>Is block number delta larger than kBlocks >> False</p>\n</li>\n<li>\n<p>Set</p>\n<p>a) y = 52k$</p>\n<p>b) x = 52k$ - 40*1600 = -12k$</p>\n</li>\n<li>\n<p>Is Sign of x (-12k$) is different from sign of y (52k$) >> True</p>\n</li>\n<li>\n<p>Compute dynamic Fee as G(-12k$,0): 0.47 bp</p>\n</li>\n<li>\n<p>Send user 40 * 1600 * (1-0.47 bp) = 63,997 sUSD</p>\n</li>\n</ol>\n</li>\n</ul>\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<ul>\n<li>$u_{0}$ and $u_{1}$ can be configurable per synth, allowing the Spartan Council to fine-tune slippage based on the asset in mind.</li>\n<li><code>atomicKBlocks</code> would also be configurable per synth, specifying the number of block intervals at which slippage resets</li>\n<li><code>maxAtomicDynamicFee</code></li>\n</ul>\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":"b24162b4-2471-5b37-b715-b3e427f44417","frontmatter__sip":272,"__params":{"frontmatter__sip":"272"}}},"staticQueryHashes":[]}