# How to Add a Market as a Solver

### Listing a Market

#### Step 1: Modify the Muon Oracle

To add a new market as a solver, first add the new price source to the Muon Oracle. This involves modifying the function to fetch prices from the new source and then integrating it with the existing price fetching function. The repo to modify can be found[ here](https://github.com/SYMM-IO/protocol-muon-crypto). Here's the relevant code to modify if the market isn't available on Binance, Kucoin or MEXC:

```javascript
async function getNewExchangePrices() {
    return withSpan(
        getNewExchangePrices.name,
        spanTypes.newExchangePriceFetch, // You need to define this span type
        async function () {
            const newExchangeUrl = priceUrl + "/newExchange";
            let data;
            try {
                const result = await axios.get(newExchangeUrl);
                data = result.data;
            } catch (e) {
                console.log(e);
                throw new Error("FAILED_TO_GET_NEW_EXCHANGE_PRICES");
            }
            const pricesMap = {};
            data.forEach((el) => {
                try {
                    pricesMap[el.symbol] = scaleUp(Number(el.price).toFixed(10)).toString();
                } catch (e) {}
            });
            return pricesMap;
        },
        []
    );
}
const getSorucePrices = {
    binance: getBinancePrices,
    kucoin: getKucoinPrices,
    mexc: getMexcPrices,
    newExchange: getNewExchangePrices, // Add the new exchange function here
};s
```

#### Step 2: Make a Pull Request

Once the necessary changes are made to the Muon Oracle, the next step is to create a pull request to integrate these changes into the SYMMIO codebase. Ensure that your pull request includes:

* A detailed description of the changes made.
* Any dependencies or configurations required for the new symbol.

#### Step 3: Add the Symbol to Solver Endpoints

Update your solver API endpoints to include the new symbol. This ensures that the frontends are made aware of the new markets you've made available for users to trade.

#### Step 4: Add the Market on the Contracts

This step requires a user with the `SYMBOL_MANAGER_ROLE`. In v0.8.5, symbols now have an associated **symbol type** which is used to categorize markets and control which solvers can trade them.

**Option A — Add with type in one call** using `addSymbolsWithType()`:

```solidity
SymbolWithType[] memory symbols = new SymbolWithType[](1);
symbols[0] = SymbolWithType({
    name: "SYMBOLUSDT",
    minAcceptableQuoteValue: 10e18,
    minAcceptablePortionLF: 1e17,
    tradingFee: 5e16,           // 0.05%
    maxLeverage: 50,
    fundingRateEpochDuration: 3600,   // 1 hour
    fundingRateWindowTime: 1800,      // 30 minutes
    symbolType: 1                     // e.g.
});

diamond.addSymbolsWithType(symbols);
```

**Option B — Add the symbol first, set the type separately:**

```solidity
symbolControlFacet.addSymbol(
    "SYMBOLUSDT", //symbol name
    10e18,  // minAcceptableQuoteValue
    1e17,   // minAcceptablePortionLF
    5e16,   // tradingFee (0.05%)
    50,     // maxLeverage
    3600,   // fundingRateEpochDuration (1 hour)
    1800    // fundingRateWindowTime (30 minutes)
);

	function setSymbolTypes(uint256[] calldata symbolIds, uint256[] calldata symbolTypes) external onlyRole(LibAccessibility.SYMBOL_MANAGER_ROLE) {
		require(symbolIds.length == symbolTypes.length, "SymbolControlFacet: Array length mismatch");
		for (uint256 i = 0; i < symbolIds.length; i++) {
			setSymbolTypeInternal(symbolIds[i], symbolTypes[i]);
		}
	}
```

> **Note:** Adding symbols on the contracts is still permissioned (requires `SYMBOL_MANAGER_ROLE`) However, the solver-side steps that follow (whitelisting) are fully self-service.

#### Step 5: Whitelist the Symbol for Your Solver (Party B)

Once the symbol exists on the contracts, the solver (Party B) needs to opt in to trading it. This step is — either the Party B address itself or an account with the `PARTY_B_MANAGER_ROLE` can perform it.&#x20;

You have two approaches:

**Whitelist by symbol type** — opt in to an entire category at once:

```solidity
diamond.whitelistSymbolType(partyBAddress, 1);
```

This means any current or future symbol with `symbolType = 1` is automatically accepted.

**Whitelist individual symbols** — opt in to specific symbols only:

```solidity
uint256[] memory symbolIds = new uint256[](2);
symbolIds[0] = 42; // SYMBOLUSDT
symbolIds[1] = 43; // SYMBOL2USDT
diamond.whitelistSymbols(partyBAddress, symbolIds);
```

### De-Listing a Market

**Step 1: Announce the Delisting**

The first step in de-listing a market is to communicate the upcoming changes to both frontends (FEs) and users. This includes announcing:

* The specific markets that will be delisted.
* The date when the delisting will take effect.
* Any other relevant information such as the last date to open new positions in these markets.

**Step 2: Stop Accepting New Positions**

After the announcement, you should ensure that no new positions are accepted for the markets that are scheduled for delisting. This can be internally achieved by modifying the relevant API endpoints so that these markets are no longer accepting quotes.&#x20;

**Remove individual symbols from your whitelist:**

```solidity
uint256[] memory symbolIds = new uint256[](1);
symbolIds[0] = 42; // the symbol being delisted
diamond.removeSymbolsFromWhitelist(partyBAddress, symbolIds);
```

**Remove an entire symbol type from your whitelist:**

```solidity
diamond.removeSymbolTypeFromWhitelist(partyBAddress, 1); 
```

**Blacklisting specific symbols:** useful if the symbol's type is still whitelisted but you want to exclude individual symbols:

```solidity
uint256[] memory symbolIds = new uint256[](1);
symbolIds[0] = 42;
diamond.blacklistSymbols(partyBAddress, symbolIds);
```

**Step 3: Activating the Emergency Status**

In the current implementation, there is a [function](https://docs.symm.io/contract-documentation/symmio-perps-v0.8.5/diamond-core-facets/control-facet) that allows the admin to activate and deactivate the emergency status of your partyB. This emergency status enables you to manage the closing of existing positions for the delisted markets.

To do this:

1. **Activate Emergency Status**: Use the contract to activate the emergency status for the relevant markets. This should be done once the delisting date is reached or as part of the delisting process.
2. **Close Positions**: Existing positions should be closed using the Muon market price as the settlement price. After delisting, the Muon market price will default to the settlement price of Binance. You typically have a one-month window after the delisting to ensure all positions are closed in an orderly fashion. Information on how the settlement price is calculated can be found [here](https://www.binance.com/en/support/faq/delivery-and-settlement-of-quarterly-futures-a3401595e1734084959c61491bc0dbe3) (Binance)
