SIP-390: Minimum Credit Patch - Perps V3
Author | |
---|---|
Status | Implemented |
Type | Governance |
Network | Base |
Implementor | TBD |
Release | TBD |
Proposal | Loading status... |
Created | 2024-06-05 |
Simple Summary
This sip proposes to patch the minimum credit calculation by incorporating the escrowed snxUSD margin deposited by traders into a perp market.
Abstract
Some concepts covering this SIP:
- Credit capacity represents the total amount of snxUSD that the market could withdraw if it were to immediately unwrap all its positions.
- Locked credit represents the minimum amount of delegated collateral that needs to be credited to a given market, in order to allows traders to withdraw from a given market.
The validation done in the core of the system uses these concepts whereby creditCapacityD18
is calculated by summing up the value of the delegated collateral of LP's but also includes traders margin. However, lockedCredit
does not include the latter margin amount, hence this sip.
Currently, minimum credit is calculated by iterating on over active markets, getting the active open interest and multiplying that by a lockedOiRatio
, this gives insight information on the expected credit that needs to be catered for by LP's.
Motivation
The minimum credit calculation update ensures that markets are sufficiently covered by liquidity from LP's before allowing withdrawals / undelegation from a given market. This provides confidence to traders that markets are solvent and assurances on it's collateralization.
Rationale
The original validation did not take into account that traders' margin are included credit capacity. This patch only needs to be applied to snxUSD, while other spot synths, deposited by traders are not included into creditCapacity
calculation by the core system.
Technical Specification
The fix ensures that the snxUSD
deposited by traders as margin is incorporated into the minimum credit calculation as done in PR-2144.
function minimumCredit(
Data storage self
) internal view returns (uint256 accumulatedMinimumCredit) {
uint256 activeMarketsLength = self.activeMarkets.length();
for (uint256 i = 1; i <= activeMarketsLength; i++) {
uint128 marketId = self.activeMarkets.valueAt(i).to128();
accumulatedMinimumCredit += PerpsMarket.requiredCredit(marketId);
}
// add the sUSD collateral value to the minimum credit since it's used as escrow
accumulatedMinimumCredit += self.collateralAmounts[SNX_USD_MARKET_ID];
}
Test Cases
Relevant tests will be developed during implementation.
Configurable Values (Via SCCP)
N/A
Copyright
Copyright and related rights waived via CC0.