{"componentChunkName":"component---src-pages-sips-sip-markdown-remark-frontmatter-sip-tsx","path":"/sips/sip-246/","result":{"data":{"markdownRemark":{"fileAbsolutePath":"/vercel/path0/content/sips/sip-246.md","frontmatter":{"sip":246,"sccp":null,"title":"Upgrade Collateral Short","network":"Optimism","author":"MEB, Matt, Ethernaut","type":"Governance","proposal":"https://snapshot.org/#/snxgov.eth/proposal/QmbsiEejUWFnQFoAfJguvon7QE7ZxwcbQezS46gFXMTueP","implementor":null,"release":"Kochab","created":"2022-05-31T00:00:00.000Z","updated":null,"status":"Implemented"},"html":"<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 an upgrade for the Collateral Short contract to fix a few accounting bugs recently discovered in the contract. It also introduces an owner function to be able to purge debt from the old contract and removes the collapseFeeRate (currently unused).</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>An accounting bug in the Synthetix shorting contract was causing excess debt to accumulate in the shorting contract without being automatically burnt. While the issue was solved by burning excess debt, the opening of new shorts was paused while fixes were conducted.</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 where you explain the reasoning behind how you propose to solve the problem. Why did you propose to implement the change in this way, what were the considerations and trade-offs? The rationale fleshes out what motivated the design and why particular design decisions were made. It should describe alternate designs that were considered and related work. The rationale may also provide evidence of consensus within the community, and should discuss important objections or concerns raised during discussion.-->\n<p>To make sure sUSD is burnt when closing with collateral and debt does not accumulate.</p>\n<p>Furthermore, the ability to move users to an upgraded contract ensures that partners do not need to complete any actions when we must upgrade our contracts. Partners like Lyra rely heavily on the collateral shorts contract.</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<p>This SIP requires a general refactoring of the <code>_repayWithCollateral</code> function to account for the proper fees to be paid and to update balances accordingly.</p>\n<p>Most importantly, it must implement the burning of sUSD synths in the contract when repaying a loan with collateral:</p>\n<pre><code>_synthsUSD().burn(address(this), collateralToRemove);\n</code></pre>\n<p>Additionally, this SIP requires the introduction of an <code>onlyOwner</code> function, called <code>upgradeCollateralShort</code>, that allows for the burning of excess sUSD in the legacy CollateralShort contract as needed:</p>\n<pre><code>   /**\n    * Function used to migrate balances from the CollateralShort contract\n    * @param short The address of the CollateralShort contract to be upgraded\n    * @param amount The amount of sUSD collateral to be burnt\n    */\n   function upgradeCollateralShort(address short, uint amount) external onlyOwner {\n       require(short == resolver.getAddress(\"CollateralShortLegacy\"), \"Issuer: wrong short address\");\n       require(address(synths[sUSD]) != address(0), \"Issuer: synth doesn't exist\");\n       require(amount > 0, \"Issuer: cannot burn 0 synths\");\n \n       exchanger().settle(short, sUSD);\n \n       synths[sUSD].burn(short, amount);\n   }\n</code></pre>\n<p>Note: the legacy CollateralShort contract must be added to the AddressResolver as <code>”CollateralShortLegacy”</code> in order for this owner function to work as intended. This is to distinguish the older contract from the newly deployed contract which will be known in the resolver as <code>CollateralShort</code>.</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<pre><code>// For `_repayWithCollateral`, it should pay the relevant fees and balances should update accordingly\n\n// The fee pool should have received fees (exchange + accrued interest)\nassert.deepEqual(\n  await sUSDSynth.balanceOf(FEE_ADDRESS),\n  beforeFeePoolBalance.add(sUSDAccruedInterest).add(exchangeFee),\n  'The fee pool did not receive enough fees'\n);\n\n// The loan amount should have been reduced by the expected amount\n// amountRepaid might be less than ethAmountToRepay if there's accrued interest\nassert.deepEqual(\n  loan.amount,\n  ethAmountToShort.sub(amountRepaid),\n  'The loan amount was not reduced correctly'\n);\n\n// The loan collateral should have been reduced by the expected amount\nassert.deepEqual(\n  loan.collateral,\n  beforeLoanCollateral.sub(collateralToUse),\n  'The loan collateral was not reduced correctly'\n);\n\n// The contract sUSD balance should have been reduced by the expected amount\nassert.deepEqual(\n  await sUSDSynth.balanceOf(short.address),\n  beforeShortBalance.sub(collateralToUse),\n  'The short contracts holds excess sUSD'\n);\n\n// The user sUSD balance should remain unchanged\nassert.deepEqual(\n  await sUSDSynth.balanceOf(account1),\n  beforeUserBalance,\n  'The user sUSD balance is unexpected'\n);\n</code></pre>\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<p>Removed <code>collapseFeeRate</code> for the sake of reducing complexity and since it was not being utilized.</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":"8dc1e990-cf34-5c03-8e60-3ee7df8f0536","frontmatter__sip":246,"__params":{"frontmatter__sip":"246"}}},"staticQueryHashes":[]}