Muon
Base Client
The MuonClient
class is designed as a base client for making HTTP requests to the Muon network. It is part of a larger infrastructure that aims to interact with the Muon network for obtaining signatures necessary for verifying sensitive transactions such as opening and closing trades. The signatures are crucial for confirming a user's unrealized profit and loss (upnl) and the price of an asset.
This client leverages a utility function makeHttpRequest
to perform the actual network request. The class is structured to easily construct URLs with the necessary parameters and handle the responses from the Muon network.
Constructor
The constructor accepts a configuration object with a single property, APP_METHOD
, which specifies the method to be used in the Muon network request.
Parameters
APP_METHOD
: A string that defines the method to be appended to the request URL, indicating the action to be performed on the Muon network.
Methods
_sendRequest
This async method constructs the request URL with the necessary parameters and performs the HTTP request to the Muon network.
Parameters
baseUrl
: The base URL of the Muon network endpoint.appName
: The name of the application making the request, used as a parameter in the request URL.requestParams
: An array of key-value pairs representing additional parameters to be included in the request.
Returns
A Promise that resolves to the response from the Muon network. The response is an object containing at least two properties: result
, which holds the data returned by the request, and success
, a boolean indicating whether the request was successful.
Errors
Throws an error if the request fails due to network issues or if the Muon network returns an error response. Errors are logged to the console.
Quotes Client
Overview
The QuotesClient
class extends MuonClient
to interact with the Muon network for the purpose of fetching the price of a symbol with the upnl of partyA
. In order to send a quote, the signature received must be verified on the SYMM contract side.
Constructor
Initializes the QuotesClient
with a predefined Muon app method uPnl_A_withSymbolPrice
, setting up the client for fetching quotes related to uPnl and symbol prices.
Static Methods
createInstance
createInstance
A factory method to conditionally create an instance of QuotesClient
based on whether the functionality is enabled.
Parameters
isEnabled
: A boolean flag indicating if the instance should be created.
Returns
Returns an instance of
QuotesClient
ifisEnabled
istrue
; otherwise, returnsnull
.
Private Methods
_getRequestParams
_getRequestParams
Constructs and validates the request parameters necessary for the Muon network request.
Parameters
account
: The account address involved in the query.chainId
: The chain ID.contractAddress
: The contract address.marketId
: The market id.
Returns
An array of key-value pairs representing the request parameters if all parameters are valid.
An
Error
object if any required parameter is missing.
Public Methods
getMuonSig
getMuonSig
Fetches the Muon signature for a given account and transaction details by making requests to a series of URLs until a successful response is obtained.
Parameters
account
: The account address for which the signature is being requested.appName
: The name of the application making the request.urls
: An array of URLs to the Muon network endpoints.chainId
: The chain id.contractAddress
: Optional contract address on the blockchain.marketId
: Optional market identifier.
Returns
The Muon signature.
An object containing the success status and the error if the request fails.
Deallocate Client
Overview
DeallocateClient
is a specialized class derived from MuonClient
aimed at supporting the deallocation process. It verifies a user's unrealized profit and loss (uPnl) to determine their eligibility for returning their allocated capital back to their deposits. This is particularly useful in scenarios where the capital might be maintaining open trading positions.
Constructor
Initializes DeallocateClient
with a specific application method uPnl_A
, configuring it for the upnl verification process necessary for deallocation.
Static Methods
createInstance
createInstance
Factory method to conditionally create an instance of DeallocateClient
based on a boolean flag.
Parameters
isEnabled
: Determines whether an instance ofDeallocateClient
should be created.
Returns
An instance of
DeallocateClient
ifisEnabled
istrue
; otherwise,null
.
Last updated