From b7cddb8378430c14af67ccc43443ccec98ec39e4 Mon Sep 17 00:00:00 2001 From: Noisekit Date: Wed, 28 Jun 2023 14:47:49 +0800 Subject: [PATCH] SIP-330: Minimum collateral capacity view function and event --- content/sips/sip-330.md | 75 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 content/sips/sip-330.md diff --git a/content/sips/sip-330.md b/content/sips/sip-330.md new file mode 100644 index 000000000..9ba4693be --- /dev/null +++ b/content/sips/sip-330.md @@ -0,0 +1,75 @@ +--- +sip: 330 +title: Minimum credit capacity view function and event +network: Ethereum & Optimism +status: Draft +type: Governance +author: Noisekit +implementor: TBD +created: 2023-06-28 +--- + +## Simple Summary + +This proposal suggests the addition of a view function that provides the minimum credit capacity of a market, required to maintain market liquidity, and an event that is emitted when capacity changes. + +## Abstract + +A `getMinimumCreditCapacity(uint128 marketId)` function would return the minimum collateral needed for a given market to avoid getting locked due to insufficient collateral. In addition, a `MinimumCreditCapacityChanged(uint128 marketId, uint128 oldCreditCapacity, uint128 newCreditCapacity)` event would be emitted whenever the minimum collateral capacity changes. + +## Motivation + +The proposed additions will improve the user experience on the frontend by allowing users to understand how much collateral they can withdraw without causing a transaction revert due to a market getting into a locked collateral state. + +For example, if a user wanted to decrease delegated collateral amount, the application could call `getMinimumCreditCapacity` to calculate the maximum amount the user could withdraw without causing a revert (losing user's money for gas fees) + +In addition, the event would enable the creation of a historical data chart or dashboard to track changes in market liquidity requirements over time. + +## Specification + +### Overview + +These additions would use existing data structures in the Synthetix V3 core system and should not introduce substantial risk to the system. + +### Rationale + +Providing visibility into minimum collateral requirements and changes to them helps users make informed decisions about their participation in the Synthetix Protocol. + +### Technical Specification + +The `getMinimumCreditCapacity` function could be implemented as follows: + +```solidity + function getMinimumCreditCapacity( + uint128 marketId + ) + external + view + returns (uint128 minCreditCapacity) + { + // Implementation to calculate and return the minimum collateral requirement + } +``` + +The `MinimumCreditCapacityChanged` event could be emitted as follows: + +```solidity + event MinimumCreditCapacityChanged( + uint128 indexed marketId, + uint128 oldCreditCapacity, + uint128 newCreditCapacity + ); + + // This could be emitted wherever the minimum collateral requirement for a market changes in the system +``` + +## Test Case +Applications could call the `getMinimumCreditCapacity` function to display the minimum collateral needed to maintain liquidity for a given market. + +Application could listen for the `MinimumCreditCapacityChanged` event being emitted when collateral delegation changes for a given market or market configuration changes. + +## Configurable Values (Via SCCP) +N/A + +## Copyright +Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/).