Control Facet
The ControlFacet
serves as a critical component for administrative control and operational management within the system. This facet allows authorized users to perform essential functions such as transferring ownership, managing roles, and registering or deregistering entities. It also provides mechanisms to adjust operational parameters like cooldowns, penalties, and configuration settings for associated contracts and storage structures. By centralizing these capabilities, the ControlFacet
ensures that administrative tasks are performed securely and efficiently.
Function Overview
transferOwnership()
Description: Transfers the ownership of the Diamond contract to another address. LibDiamond.setContractOwner
emits an OwnershipTransferred
event.
Input Parameters:
owner
: the address of the new owner.
Storage Interactions: Updates the ds.contractOwner
in DiamondStorage
.
Event Structure
setAdmin()
Description: Grants an address with the DEFAULT_ADMIN_ROLE
.
Input Parameters:
user
: the address of the new admin.
Storage Interactions: Updates the hasRole
mapping in GlobalAppStorage
.
Event Structure
grantRole()
Description: Grants an address with a bytes32role
.
Input Parameters:
user
: the address of the new admin.role
: the keccak256 hash of the role.
Storage Interactions: Updates the hasRole
mapping in GlobalAppStorage
.
Event Structure
revokeRole()
()
Description: Revokes a specified role from an address. This function ensures that the specified user no longer holds the privileges associated with the role.
Input Parameters:
user: The address from which the role is to be revoked.
role: The
bytes32
hash of the role being revoked.
Storage Interactions:
Updates the
hasRole
mapping inGlobalAppStorage
, setting the specified role for the given user tofalse
.
Event Structure:
registerPartyB()
Description: Registers an address as "Party B" within the system.
Input Parameters:
partyB
: The address to be registered as Party B.
Storage Interactions:
Updates the
partyBStatus
mapping inMAStorage
totrue
, indicating that the address is registered as Party B.Adds the address to the
partyBList
inMAStorage
.
Event Structure:
deregisterPartyB()
Description: Removes an address from the registered "Party B" list within the system.
Input Parameters:
partyB
: The address to be deregistered as Party B.index
: The position of the address in thepartyBList
to ensure accurate and safe removal.
Storage Interactions:
Sets
partyBStatus
for the address inMAStorage
tofalse
, indicating that it is no longer registered.Replaces the entry at the specified
index
inpartyBList
with the last item in the list and then removes the last item.
Event Structure:
setMuonConfig()
Description: Configures the operational parameters related to the Muon network.
Input Parameters:
upnlValidTime
: The duration that the UPnL data remains valid.priceValidTime
: The duration that the price data is considered valid.priceQuantityValidTime
: The duration for which the price quantity data remains valid.
Storage Interactions:
Updates the
upnlValidTime
,priceValidTime
, andpriceQuantityValidTime
inMuonStorage
.
Event Structure:
setMuonIds()
Description: Sets the identifiers and gateway address associated with the Muon network configuration for the system. These settings are vital for securing and validating interactions with the Muon network.
Input Parameters:
muonAppId: The application ID for the Muon network.
validGateway: The address of the gateway used for Muon network validations.
publicKey: A
PublicKey
struct containing the elliptic curve public key (x
coordinate andparity
) used for cryptographic operations in the Muon network.
Storage Interactions:
Updates the
muonAppId
,validGateway
, andmuonPublicKey
inMuonStorage
. These parameters are crucial for ensuring that the system communicates correctly and securely with the Muon network.
Event Structure:
setCollateral()
Description: Configures the primary collateral type used within the system. This function sets a specific ERC20 token as the collateral for transactions and operations.
Input Parameters:
collateral
: The address of the ERC20 token to be set as collateral.
Storage Interactions:
Validates the current balance of any previously set collateral to ensure it is zero before proceeding.
Updates the
collateral
address inGlobalAppStorage
to the new token address specified, ensuring that all future transactions use the newly specified token as collateral.
Event Structure:
addSymbol()
Description: Registers a new trading symbol within the system. This function sets variables such as the minimum quote value, leverage, trading fee, and the parameters governing the funding rate.
Input Parameters:
name
: The name of the symbol to be registered.minAcceptableQuoteValue
: The minimum value of a quote for the symbol to be considered valid.minAcceptablePortionLF
: The minimum portion assigned as a liquidator fee, awarded to the liquidator.tradingFee
: The fee charged per trade.maxLeverage
: The maximum leverage allowed for trading this symbol.fundingRateEpochDuration
: The duration of each funding rate epoch, during which interest rates are recalculated.fundingRateWindowTime
: The window of time within an epoch when the funding rate can be changed.
Storage Interactions:
Increments the
lastId
inSymbolStorage
to assign a unique ID to the new symbol.Stores the new symbol parameters in the
symbols
mapping ofSymbolStorage
, associating them with the newly incremented symbol ID.
Event Structure:
addSymbols()
Description: Facilitates the batch registration of multiple trading symbols within the system. This function leverages the addSymbol
function to register each symbol in the provided array.
Input Parameters:
symbols: An array of
Symbol
structs, each containing the necessary parameters to register a new trading symbol. EachSymbol
struct includes:\name
: The name of the symbol to be registered.minAcceptableQuoteValue
: The minimum value of a quote for the symbol to be considered valid.minAcceptablePortionLF
: The minimum portion assigned as a liquidator fee, awarded to the liquidator.tradingFee
: The fee charged per trade, expressed in token units to a precision of 18 decimals.maxLeverage
: The maximum leverage allowed for trading this symbol.fundingRateEpochDuration
: The duration of each funding rate epoch, during which interest rates are recalculated.fundingRateWindowTime
: The window of time within an epoch when the funding rate can be changed.
Storage Interactions:
Calls the
addSymbol
function for each symbol in the array, which handles all storage interactions such as updating theSymbolStorage
with new symbol IDs and their respective parameters.
setSymbolFundingState()
Description: Adjusts the funding rate parameters for a specific trading symbol within the system.
Input Parameters:
symbolId
: The unique identifier of the symbol for which the funding state is being set.fundingRateEpochDuration
: The total duration of the funding rate epoch.fundingRateWindowTime
: The window of time within an epoch when the funding rate can be changed.
Storage Interactions:
Updates the fundingRateEpochDuration
and fundingRateWindowTime
for the specified symbol in SymbolStorage
, ensuring that the symbol's financial operations adhere to the newly defined timings.
Event Structure:
setSymbolMaxLeverage()
Description: Adjusts the maximum leverage allowed for a specific trading symbol within the platform.
Input Parameters:
symbolId
: The identifier of the symbol for which the maximum leverage is being set.maxLeverage
: The new maximum leverage value to be set for the symbol.
Storage Interactions:
Updates the
maxLeverage
parameter for the specified symbol inSymbolStorage
.
Event Structure:
setSymbolAcceptableValues()
Description: Updates the minimum acceptable quote value and the minimum acceptable portion of liquidator fees (LF) for a specific trading symbol.
Input Parameters:
symbolId
: The identifier of the symbol for which the values are being set.minAcceptableQuoteValue
: The new minimum quote value that must be met for trading transactions involving this symbol to be considered valid.minAcceptablePortionLF
: The new minimum liquidator fee portion awarded to the liquidator for transactions involving this symbol.
Storage Interactions:
Verifies the validity of the
symbolId
within the range of registered symbols inSymbolStorage
.Updates the
minAcceptableQuoteValue
andminAcceptablePortionLF
for the specified symbol inSymbolStorage
, ensuring that trading parameters align with the platform's financial and risk management policies.
Event Structure:
setSymbolTradingFee()
Description: Adjusts the trading fee for a specific trading symbol within the system.
Input Parameters:
symbolId
: The identifier of the symbol for which the trading fee is being set.tradingFee
: The new trading fee amount.
Storage Interactions:
Validates the existence of the symbol by checking if the
symbolId
is within the valid range of registered symbols inSymbolStorage
.Updates the
tradingFee
for the specified symbol inSymbolStorage
.
Event Structure:
setDeallocateCooldown()
Description: Sets the cooldown period for deallocation actions within the system.
Input Parameters:
deallocateCooldown
: The duration (in seconds) to set as the new cooldown period for deallocation actions.
Storage Interactions:
Updates the
deallocateCooldown
inMAStorage
.
Event Structure:
setForceCancelCooldown()
Description: Sets the cooldown period for force cancellation actions.
Input Parameters:
forceCancelCooldown
: The duration (in seconds) to set as the new cooldown period for force cancellation actions.
Storage Interactions:
Updates the
forceCancelCooldown
inMAStorage
. This modification directly influences the minimum time interval between requesting a cancel and performing a force cancel action.
Event Structure:
setForceCloseCooldown()
Description: Adjusts the cooldown period for force close action.
Input Parameters:
forceCloseCooldown
: The duration (in seconds) to set as the new cooldown period for force close actions.
Storage Interactions:
Updates the
forceCloseCooldown
inMAStorage
. This modification directly influences the minimum time interval between requesting a close and performing a force close action.
Event Structure:
setForceCancelCloseCooldown()
Description: Sets the cooldown period for the force cancellation of close actions within the system.
Input Parameters:
forceCancelCloseCooldown
: The duration (in seconds) to set as the new cooldown period for cancelling force close actions.
Storage Interactions:
Updates the
forceCancelCloseCooldown
inMAStorage
.
Event Structure:
setLiquidatorShare()
Description: Adjusts the share percentage that a liquidator receives when executing a liquidation action.
Input Parameters:
liquidatorShare
: The new percentage (expressed as a fraction of 1e18 for precision) that a liquidator will receive as a reward for executing a liquidation.
Storage Interactions:
Updates the
liquidatorShare
inMAStorage
.
Event Structure:
setForceCloseGapRatio()
Description: Configures the ratio used to determine the gap between the market price and the trigger price for force-close actions.
Input Parameters:
forceCloseGapRatio
: The new gap ratio applied to the requestedClosePrice which allows a user to force close a position.
Storage Interactions:
Updates the
forceCloseGapRatio
inMAStorage
.
Event Structure:
setPendingQuotesValidLength()
Description: Sets the maximum amount of valid pending quotes for a partyA.
Input Parameters:
pendingQuotesValidLength
: The maximum amount of pending quotes at one time for partyA.
Storage Interactions:
Updates the
pendingQuotesValidLength
inMAStorage
. This adjustment ensures that the system accurately reflects the operational window for executing trades based on received quotes, adapting to market dynamics or regulatory requirements.
Event Structure:
Pause/Miscellaneous functions
setFeeCollector()
Purpose: Assigns the feeCollector
address responsible for receiving system fees. Ensures the address is non-zero and updates GlobalAppStorage
.
pauseGlobal()
Purpose: Pauses all global operations within the system. Sets globalPaused
to true in GlobalAppStorage
.
pauseLiquidation()
Purpose: Temporarily halts all liquidation processes. Activates the liquidationPaused
state in GlobalAppStorage
.
pauseAccounting()
Purpose: Suspends all accounting activities, setting accountingPaused
to true in GlobalAppStorage
.
pausePartyAActions()
Purpose: Freezes all actions by Party A, setting partyAActionsPaused
to true in GlobalAppStorage
.
pausePartyBActions()
Purpose: Disables all operational actions for Party B, setting partyBActionsPaused
to true in GlobalAppStorage
.
activeEmergencyMode()
Purpose: Activates emergency mode across the system, setting emergencyMode
to true in GlobalAppStorage
.
unpauseGlobal()
Purpose: Resumes all previously paused global operations by setting globalPaused
to false in GlobalAppStorage
.
unpauseLiquidation()
Purpose: Reactivates liquidation processes by setting liquidationPaused
to false in GlobalAppStorage
.
unpauseAccounting()
Purpose: Resumes all accounting activities by setting accountingPaused
to false in GlobalAppStorage
.
unpausePartyAActions()
Purpose: Allows Party A to resume normal operations by setting partyAActionsPaused
to false in GlobalAppStorage
.
unpausePartyBActions()
Purpose: Re-enables Party B actions by setting partyBActionsPaused
to false in GlobalAppStorage
.
setLiquidationTimeout()
Purpose: Sets the timeout period for liquidations, updating the liquidationTimeout
in MAStorage
.
suspendedAddress()
Purpose: Suspends activities for a specified user address, ensuring it is non-zero and updating suspendedAddresses
in AccountStorage
.
unsuspendedAddress()
Purpose: Lifts suspension on a specified user address, ensuring it is non-zero and updating suspendedAddresses
in AccountStorage
.
deactiveEmergencyMode()
Purpose: Deactivates emergency mode across the system, updating emergencyMode
in GlobalAppStorage
.
setBalanceLimitPerUser()
Purpose: Sets the maximum balance limit per user, updating this value in GlobalAppStorage
.
setPartyBEmergencyStatus()
Purpose: Sets the emergency status for multiple Party B addresses, ensuring non-zero addresses and updating partyBEmergencyStatus
in GlobalAppStorage
.
Last updated