SIP-136: Improve debt cache total issued synths calculation (v2)
Author | |
---|---|
Status | Implemented |
Type | Governance |
Implementor | TBD |
Release | TBD |
Discussions-To | https://research.synthetix.io/ |
Created | 2021-05-06 |
Simple Summary
This SIP proposes to improve the debt pool / debt cache calculation of total issued synths (the debt pool) that are backed by SNX stakers and the synths supply that is issued by other types of collateral.
Overview
With the introduction of Ether collateral loans in SIP 85 and Multi-collateral loans in SIP 97, sETH and sUSD synths could be issued with ETH and renBTC collateral. This sETH and sUSD issued by the Ether Collateral and loans are excluded from the debt that SNX stakers owe, with the supply excluded from the synths.totalSupply()
in the debt cache. However the current debt pool calculations don't factor in that when the sUSD or sETH synths are exchanged for another synth, the total supply of sUSD / sETH could be less than the total issued amount backed by non-SNX collateral.
To support the upcoming Ether Wrapper contract in SIP 112 which allows ETH / wETH to mint sETH directly, the debt pool will be calculated as Total supply of Synths in USD - Excluded Supply from Debt Pool in USD
.
The excluded supply consists of:
- Total issued sETH and sUSD synths from EtherCollateral loans.
- Total issued sETH, sBTC and sUSD synths from Multi-collateral loans.
- Total Shorts value issued in Collateral Shorts.
- Total issued sETH and sUSD synths from Ether Wrapper.
It has also been discovered that non-SNX debt was not being excluded correctly, during the partial update of the debt cache in the exchange logic.
Rationale
By calculating the total excluded debt from EtherCollateral loans, multi-collateral loans, collateral shorts and ETH wrapper in USD, this value can be subtracted from all of the circulating Synth's total supply to determine the debt pool size.
The excluded debt takes into consideration that sUSD, sETH, sBTC issued against ETH or renBTC collateral can be exchanged into another synth. Currently on mainnet there could be an edge case where if the multicollateral synth's total supply is less than the amount that is backed by other collateral, it would not exclude the correct amount of debt that is excluded from SNX staker's debt pool.
Technical Specification
Introduce a new function, DebtCache.totalNonSnxBackedDebt
, to return the total excluded debt.
function totalNonSnxBackedDebt() external view returns (uint excludedDebt, bool isInvalid);
Update BaseDebtCache._issuedSynthValues()
to return only the USD values of each synth's total supply, and move calculations related to excluding debt up into BaseDebtCache.currentDebt
.
Fix DebtCache._updateCachedSynthDebtsWithRates
by excluding non-SNX debt from the cached debt update.
Test Cases
Unit tests included with implementation.
Configurable Values (Via SCCP)
N/A
Copyright
Copyright and related rights waived via CC0.