> For the complete documentation index, see [llms.txt](https://symmdocs.gitbook.io/frontend-sdk-technical-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://symmdocs.gitbook.io/frontend-sdk-technical-docs/frontend-sdk/core-package/lib/muon.md).

# 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

```typescript
constructor({ APP_METHOD }: { APP_METHOD: string })
```

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`**

```typescript
public async _sendRequest(baseUrl: string, appName: string, requestParams: string[][])
```

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

```typescript
  constructor() {
    super({ APP_METHOD: "uPnl_A_withSymbolPrice" });
  }
```

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`

```typescript
static createInstance(isEnabled: boolean): QuotesClient | null
```

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` if `isEnabled` is `true`; otherwise, returns `null`.

### Private Methods

#### `_getRequestParams`

```typescript
private _getRequestParams(account: string | null, chainId?: number, contractAddress?: string, marketId?: number): string[][] | Error
```

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`

```typescript
public async getMuonSig(account: string | null, appName: string, urls: string[], chainId?: number, contractAddress?: string, marketId?: number)
```

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

```typescript
  constructor() {
    super({ APP_METHOD: "uPnl_A" });
  }
```

Initializes `DeallocateClient` with a specific application method `uPnl_A`, configuring it for the upnl verification process necessary for deallocation.

### Static Methods

#### `createInstance`

```typescript
static createInstance(isEnabled: boolean): DeallocateClient | null
```

Factory method to conditionally create an instance of `DeallocateClient` based on a boolean flag.

**Parameters**

* `isEnabled`: Determines whether an instance of `DeallocateClient` should be created.

**Returns**

* An instance of `DeallocateClient` if `isEnabled` is `true`; otherwise, `null`.
